Skip to content

Commit

Permalink
Merge pull request #7 from Returnless-com/credit_memo
Browse files Browse the repository at this point in the history
Credit memo
  • Loading branch information
sedonik authored Aug 16, 2022
2 parents 3baf6c0 + a748ad4 commit 7cffccf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions Model/Api/OrderCreditMemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Returnless\Connector\Helper\Data as RetHelper;
use Magento\Sales\Model\Order\CreditmemoFactory;
use Magento\Sales\Model\Service\CreditmemoService;
use Magento\Sales\Api\CreditmemoManagementInterface;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
use Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader;
Expand Down Expand Up @@ -73,7 +74,7 @@ class OrderCreditMemo implements OrderCreditMemoInterface
* @param CreditmemoSender $creditmemoSender
* @param CreditmemoLoader $creditmemoLoader
* @param CreditmemoFactory $creditMemoFactory
* @param CreditmemoService $creditMemoService
* @param CreditmemoManagementInterface $creditMemoService
* @param Invoice $invoice
* @param RetHelper $retHelper
* @param WebsiteCollectionFactory $websiteCollection
Expand All @@ -84,7 +85,7 @@ public function __construct(
CreditmemoSender $creditMemoSender,
CreditmemoLoader $creditMemoLoader,
CreditmemoFactory $creditMemoFactory,
CreditmemoService $creditMemoService,
CreditmemoManagementInterface $creditMemoService,
Invoice $invoice,
RetHelper $retHelper,
WebsiteCollectionFactory $websiteCollection,
Expand Down Expand Up @@ -196,6 +197,18 @@ public function createCreditMemo($requestParams)
$this->creditMemoLoader->setOrderId($orderId); //pass order id
$this->creditMemoLoader->setCreditmemo($creditMemoData);

$invoiceCollection = $order->getInvoiceCollection();
foreach ($invoiceCollection as $invoice) {
$state = $invoice->getState();

if ($state != 2) {
continue;
}

$invoiceId = $invoice->getId();
$this->creditMemoLoader->setInvoiceId($invoiceId);
}

$creditMemo = $this->creditMemoLoader->load();
if ($creditMemo) {
if (!$creditMemo->isValidGrandTotal()) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"OSL-3.0",
"AFL-3.0"
],
"version": "1.2.4"
"version": "1.2.5"
}
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Returnless_Connector" setup_version="1.2.4">
<module name="Returnless_Connector" setup_version="1.2.5">
<sequence>
<module name="Magento_Sales"/>
</sequence>
Expand Down

0 comments on commit 7cffccf

Please sign in to comment.