9
9
namespace Magento \Sales \Model \Order ;
10
10
11
11
use Magento \Framework \Api \AttributeValueFactory ;
12
+ use Magento \Framework \App \ObjectManager ;
12
13
use Magento \Framework \Pricing \PriceCurrencyInterface ;
13
14
use Magento \Sales \Api \Data \CreditmemoInterface ;
14
15
use Magento \Sales \Model \AbstractModel ;
15
16
use Magento \Sales \Model \EntityInterface ;
17
+ use Magento \Sales \Model \Order \InvoiceFactory ;
16
18
17
19
/**
18
20
* Order creditmemo model
@@ -114,6 +116,11 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt
114
116
*/
115
117
protected $ priceCurrency ;
116
118
119
+ /**
120
+ * @var InvoiceFactory
121
+ */
122
+ private $ invoiceFactory ;
123
+
117
124
/**
118
125
* @param \Magento\Framework\Model\Context $context
119
126
* @param \Magento\Framework\Registry $registry
@@ -130,6 +137,7 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt
130
137
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
131
138
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
132
139
* @param array $data
140
+ * @param InvoiceFactory $invoiceFactory
133
141
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
134
142
*/
135
143
public function __construct (
@@ -147,7 +155,8 @@ public function __construct(
147
155
PriceCurrencyInterface $ priceCurrency ,
148
156
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
149
157
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
150
- array $ data = []
158
+ array $ data = [],
159
+ InvoiceFactory $ invoiceFactory = null
151
160
) {
152
161
$ this ->_creditmemoConfig = $ creditmemoConfig ;
153
162
$ this ->_orderFactory = $ orderFactory ;
@@ -157,6 +166,7 @@ public function __construct(
157
166
$ this ->_commentFactory = $ commentFactory ;
158
167
$ this ->_commentCollectionFactory = $ commentCollectionFactory ;
159
168
$ this ->priceCurrency = $ priceCurrency ;
169
+ $ this ->invoiceFactory = $ invoiceFactory ?: ObjectManager::getInstance ()->get (InvoiceFactory::class);
160
170
parent ::__construct (
161
171
$ context ,
162
172
$ registry ,
@@ -379,6 +389,9 @@ public function canRefund()
379
389
*/
380
390
public function getInvoice ()
381
391
{
392
+ if (!$ this ->getData ('invoice ' ) instanceof \Magento \Sales \Api \Data \InvoiceInterface && $ this ->getInvoiceId ()) {
393
+ $ this ->setInvoice ($ this ->invoiceFactory ->create ()->load ($ this ->getInvoiceId ()));
394
+ }
382
395
return $ this ->getData ('invoice ' );
383
396
}
384
397
@@ -1524,6 +1537,5 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\CreditmemoExtensi
1524
1537
{
1525
1538
return $ this ->_setExtensionAttributes ($ extensionAttributes );
1526
1539
}
1527
-
1528
1540
//@codeCoverageIgnoreEnd
1529
1541
}
0 commit comments