7
7
namespace Magento \Sales \Model \Order ;
8
8
9
9
use Magento \Framework \Api \AttributeValueFactory ;
10
+ use Magento \Framework \App \ObjectManager ;
10
11
use Magento \Framework \Pricing \PriceCurrencyInterface ;
11
12
use Magento \Sales \Api \Data \CreditmemoInterface ;
12
13
use Magento \Sales \Model \AbstractModel ;
13
14
use Magento \Sales \Model \EntityInterface ;
15
+ use Magento \Sales \Model \Order \InvoiceFactory ;
14
16
15
17
/**
16
18
* Order creditmemo model
@@ -112,6 +114,11 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt
112
114
*/
113
115
protected $ priceCurrency ;
114
116
117
+ /**
118
+ * @var InvoiceFactory
119
+ */
120
+ private $ invoiceFactory ;
121
+
115
122
/**
116
123
* @param \Magento\Framework\Model\Context $context
117
124
* @param \Magento\Framework\Registry $registry
@@ -128,6 +135,7 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt
128
135
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
129
136
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
130
137
* @param array $data
138
+ * @param InvoiceFactory $invoiceFactory
131
139
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
132
140
*/
133
141
public function __construct (
@@ -145,7 +153,8 @@ public function __construct(
145
153
PriceCurrencyInterface $ priceCurrency ,
146
154
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
147
155
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
148
- array $ data = []
156
+ array $ data = [],
157
+ InvoiceFactory $ invoiceFactory = null
149
158
) {
150
159
$ this ->_creditmemoConfig = $ creditmemoConfig ;
151
160
$ this ->_orderFactory = $ orderFactory ;
@@ -155,6 +164,7 @@ public function __construct(
155
164
$ this ->_commentFactory = $ commentFactory ;
156
165
$ this ->_commentCollectionFactory = $ commentCollectionFactory ;
157
166
$ this ->priceCurrency = $ priceCurrency ;
167
+ $ this ->invoiceFactory = $ invoiceFactory ?: ObjectManager::getInstance ()->get (InvoiceFactory::class);
158
168
parent ::__construct (
159
169
$ context ,
160
170
$ registry ,
@@ -377,6 +387,9 @@ public function canRefund()
377
387
*/
378
388
public function getInvoice ()
379
389
{
390
+ if (!$ this ->getData ('invoice ' ) instanceof \Magento \Sales \Api \Data \InvoiceInterface && $ this ->getInvoiceId ()) {
391
+ $ this ->setInvoice ($ this ->invoiceFactory ->create ()->load ($ this ->getInvoiceId ()));
392
+ }
380
393
return $ this ->getData ('invoice ' );
381
394
}
382
395
@@ -1505,6 +1518,5 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\CreditmemoExtensi
1505
1518
{
1506
1519
return $ this ->_setExtensionAttributes ($ extensionAttributes );
1507
1520
}
1508
-
1509
1521
//@codeCoverageIgnoreEnd
1510
1522
}
0 commit comments