1212use Magento \Framework \App \ObjectManager ;
1313use Magento \Framework \Pricing \PriceCurrencyInterface ;
1414use Magento \Sales \Api \Data \CreditmemoInterface ;
15- use Magento \Sales \Api \InvoiceRepositoryInterface ;
1615use Magento \Sales \Model \AbstractModel ;
1716use Magento \Sales \Model \EntityInterface ;
17+ use Magento \Sales \Model \InvoiceFactory ;
1818
1919/**
2020 * Order creditmemo model
@@ -117,9 +117,9 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt
117117 protected $ priceCurrency ;
118118
119119 /**
120- * @var InvoiceRepository
120+ * @var InvoiceFactory
121121 */
122- private $ invoiceRepository ;
122+ private $ invoiceFactory ;
123123
124124 /**
125125 * @param \Magento\Framework\Model\Context $context
@@ -137,7 +137,7 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt
137137 * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
138138 * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
139139 * @param array $data
140- * @param InvoiceRepository $invoiceRepository
140+ * @param InvoiceFactory $invoiceFactory
141141 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
142142 */
143143 public function __construct (
@@ -156,7 +156,7 @@ public function __construct(
156156 \Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
157157 \Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
158158 array $ data = [],
159- InvoiceRepository $ invoiceRepository = null
159+ InvoiceFactory $ invoiceFactory = null
160160 ) {
161161 $ this ->_creditmemoConfig = $ creditmemoConfig ;
162162 $ this ->_orderFactory = $ orderFactory ;
@@ -166,7 +166,7 @@ public function __construct(
166166 $ this ->_commentFactory = $ commentFactory ;
167167 $ this ->_commentCollectionFactory = $ commentCollectionFactory ;
168168 $ this ->priceCurrency = $ priceCurrency ;
169- $ this ->invoiceRepository = $ invoiceRepository ?: ObjectManager::getInstance ()->get (InvoiceRepositoryInterface ::class);
169+ $ this ->invoiceFactory = $ invoiceFactory ?: ObjectManager::getInstance ()->get (InvoiceFactory ::class);
170170 parent ::__construct (
171171 $ context ,
172172 $ registry ,
@@ -390,7 +390,7 @@ public function canRefund()
390390 public function getInvoice ()
391391 {
392392 if (!$ this ->getData ('invoice ' ) instanceof \Magento \Sales \Model \Order \Invoice && $ this ->getInvoiceId ()) {
393- $ this ->setInvoice ($ this ->invoiceRepository -> get ($ this ->getInvoiceId ()));
393+ $ this ->setInvoice ($ this ->invoiceFactory -> create ()-> load ($ this ->getInvoiceId ()));
394394 }
395395 return $ this ->getData ('invoice ' );
396396 }
@@ -404,7 +404,6 @@ public function getInvoice()
404404 public function setInvoice (Invoice $ invoice )
405405 {
406406 $ this ->setData ('invoice ' , $ invoice );
407- $ this ->setInvoiceId ($ invoice ->getId ());
408407 return $ this ;
409408 }
410409
0 commit comments