feat(dashboard,core-flows,types,utils,medusa): Order cancelations will refund payments (#10667)

* feat(order, types): Add Credit Line to order module

* chore: add action to inject credit lines

* WIP

* chore: add fixes + observe

* chore: fix balances

* chore: add canceled badge

* chore: fix i18n schema

* chore: remove redunddant query

* chore: add changeset

* chore: add credit lines for all cancel cases

* chore: add accounting total

* chore: address review & cleanup
This commit is contained in:
Riqwan Thamir
2025-01-07 07:56:28 +01:00
committed by GitHub
parent 99a06102a2
commit 47594192b7
27 changed files with 1241 additions and 1666 deletions
@@ -51,22 +51,43 @@ describe("Action: Credit Line Add", function () {
"credit_line_total": 0
}
Upon adding a credit line, the order total and the pending difference will increase making it possible for the merchant
to request the customer for a payment for an arbitrary reason, or prepare the order balance sheet to then allow
the merchant to provide a refund.
Upon adding a credit line, the current order total will decrease with the difference_sum going in
the negatives making it possible for the merchant to balance the order to then enable a refund.
{
"transaction_total": 0,
"original_order_total": 30,
"current_order_total": 60,
"pending_difference": 60,
"difference_sum": 30,
"pending_difference": 0,
"difference_sum": -30,
"paid_total": 0,
"refunded_total": 0,
"credit_line_total": 30
}
*/
it("should add credit lines", function () {
const changesWithoutActions = calculateOrderChange({
order: originalOrder,
actions: [],
options: { addActionReferenceToObject: true },
})
const changesWithoutActionsJSON = JSON.parse(
JSON.stringify(changesWithoutActions.summary)
)
expect(changesWithoutActionsJSON).toEqual({
transaction_total: 0,
original_order_total: 30,
current_order_total: 30,
pending_difference: 30,
difference_sum: 0,
paid_total: 0,
refunded_total: 0,
credit_line_total: 0,
accounting_total: 30,
})
const actions = [
{
action: ChangeActionType.CREDIT_LINE_ADD,
@@ -87,12 +108,13 @@ describe("Action: Credit Line Add", function () {
expect(sumToJSON).toEqual({
transaction_total: 0,
original_order_total: 30,
current_order_total: 60,
pending_difference: 60,
difference_sum: 30,
current_order_total: 0,
pending_difference: 0,
difference_sum: 0,
paid_total: 0,
refunded_total: 0,
credit_line_total: 30,
accounting_total: 0,
})
originalOrder.credit_lines.push({
@@ -123,12 +145,13 @@ describe("Action: Credit Line Add", function () {
expect(sumToJSONSecond).toEqual({
transaction_total: 0,
original_order_total: 30,
current_order_total: 70,
pending_difference: 70,
difference_sum: 30,
current_order_total: -10,
pending_difference: -10,
difference_sum: 0,
paid_total: 0,
refunded_total: 0,
credit_line_total: 40,
accounting_total: -10,
})
})
})
@@ -123,6 +123,7 @@ describe("Order Exchange - Actions", function () {
paid_total: 0,
refunded_total: 0,
credit_line_total: 0,
accounting_total: 312.5,
})
const toJson = JSON.parse(JSON.stringify(changes.order.items))
@@ -3059,6 +3059,7 @@ export default class OrderModuleService<
transformPropertiesToBigNumber(trxs)
const op = isRemoved ? MathBN.sub : MathBN.add
for (const trx of trxs) {
if (MathBN.gt(trx.amount, 0)) {
summary.totals.paid_total = new BigNumber(