feat(medusa): Add difference due to OrderEdit totals (#2352)
This commit is contained in:
@@ -120,6 +120,7 @@ export default class OrderEditService extends TransactionBaseService {
|
||||
discount_total: number
|
||||
tax_total: number | null
|
||||
subtotal: number
|
||||
difference_due: number
|
||||
total: number
|
||||
}> {
|
||||
const manager = this.transactionManager_ ?? this.manager_
|
||||
@@ -127,6 +128,7 @@ export default class OrderEditService extends TransactionBaseService {
|
||||
select: ["id", "order_id", "items"],
|
||||
relations: ["items", "items.tax_lines", "items.adjustments"],
|
||||
})
|
||||
|
||||
const order = await this.orderService_
|
||||
.withTransaction(manager)
|
||||
.retrieve(order_id, {
|
||||
@@ -135,6 +137,9 @@ export default class OrderEditService extends TransactionBaseService {
|
||||
"discounts.rule",
|
||||
"gift_cards",
|
||||
"region",
|
||||
"items",
|
||||
"items.tax_lines",
|
||||
"items.adjustments",
|
||||
"region.tax_rates",
|
||||
"shipping_methods",
|
||||
"shipping_methods.tax_lines",
|
||||
@@ -152,6 +157,9 @@ export default class OrderEditService extends TransactionBaseService {
|
||||
const subtotal = await totalsServiceTx.getSubtotal(computedOrder)
|
||||
const total = await totalsServiceTx.getTotal(computedOrder)
|
||||
|
||||
const orderTotal = await totalsServiceTx.getTotal(order)
|
||||
const difference_due = total - orderTotal
|
||||
|
||||
return {
|
||||
shipping_total,
|
||||
gift_card_total,
|
||||
@@ -160,6 +168,7 @@ export default class OrderEditService extends TransactionBaseService {
|
||||
tax_total,
|
||||
subtotal,
|
||||
total,
|
||||
difference_due,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,6 +507,7 @@ export default class OrderEditService extends TransactionBaseService {
|
||||
orderEdit.subtotal = totals.subtotal
|
||||
orderEdit.tax_total = totals.tax_total
|
||||
orderEdit.total = totals.total
|
||||
orderEdit.difference_due = totals.difference_due
|
||||
|
||||
return orderEdit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user