fix(utils,medusa,order,cart): fix totals when promotions are included (#9014)
* fix(utils): fix totals when promotions are included * chore: update totals calc * chore: ignore taxes when taxable amount is 0 * chore: use subtotals everywhere * chore: fix shipping totals + tests
This commit is contained in:
1 parent
3244067ee4
commit
afd0921326
12 files changed
+378
-359
No files matched your search
@@ -2053,16 +2053,17 @@ medusaIntegrationTestRunner({
|
|||||||
type: "order",
|
type: "order",
|
||||||
order: expect.objectContaining({
|
order: expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
total: 94.764,
|
total: 95.4,
|
||||||
subtotal: 100,
|
subtotal: 100,
|
||||||
tax_total: 5.364,
|
tax_total: 5.4,
|
||||||
discount_total: 10.6,
|
discount_total: 10.6,
|
||||||
discount_tax_total: 0.636,
|
discount_subtotal: 10,
|
||||||
original_total: 95.4,
|
discount_tax_total: 0.6,
|
||||||
|
original_total: 106,
|
||||||
original_tax_total: 6,
|
original_tax_total: 6,
|
||||||
item_total: 94.764,
|
item_total: 95.4,
|
||||||
item_subtotal: 100,
|
item_subtotal: 100,
|
||||||
item_tax_total: 5.364,
|
item_tax_total: 5.4,
|
||||||
original_item_total: 106,
|
original_item_total: 106,
|
||||||
original_item_subtotal: 100,
|
original_item_subtotal: 100,
|
||||||
original_item_tax_total: 6,
|
original_item_tax_total: 6,
|
||||||
@@ -2078,12 +2079,13 @@ medusaIntegrationTestRunner({
|
|||||||
product_id: product.id,
|
product_id: product.id,
|
||||||
unit_price: 100,
|
unit_price: 100,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
tax_total: 5.364,
|
tax_total: 5.4,
|
||||||
total: 94.764,
|
total: 95.4,
|
||||||
subtotal: 100,
|
subtotal: 100,
|
||||||
original_total: 106,
|
original_total: 106,
|
||||||
discount_total: 10.6,
|
discount_total: 10.6,
|
||||||
discount_tax_total: 0.636,
|
discount_subtotal: 10,
|
||||||
|
discount_tax_total: 0.6,
|
||||||
original_tax_total: 6,
|
original_tax_total: 6,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@@ -2140,7 +2142,7 @@ medusaIntegrationTestRunner({
|
|||||||
payment_collections: [
|
payment_collections: [
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
amount: 94.764,
|
amount: 95.4,
|
||||||
status: "authorized",
|
status: "authorized",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
import {
|
import { IOrderModuleService } from "@medusajs/types"
|
||||||
ICartModuleService,
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||||
IFulfillmentModuleService,
|
|
||||||
IInventoryService,
|
|
||||||
IOrderModuleService,
|
|
||||||
IPaymentModuleService,
|
|
||||||
IPricingModuleService,
|
|
||||||
IProductModuleService,
|
|
||||||
IRegionModuleService,
|
|
||||||
IStockLocationService,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
|
||||||
ContainerRegistrationKeys,
|
|
||||||
ModuleRegistrationName,
|
|
||||||
} from "@medusajs/utils"
|
|
||||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import {
|
import {
|
||||||
adminHeaders,
|
adminHeaders,
|
||||||
@@ -27,29 +14,10 @@ medusaIntegrationTestRunner({
|
|||||||
env,
|
env,
|
||||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let appContainer
|
let appContainer
|
||||||
let cartModuleService: ICartModuleService
|
|
||||||
let regionModuleService: IRegionModuleService
|
|
||||||
let productModule: IProductModuleService
|
|
||||||
let paymentModule: IPaymentModuleService
|
|
||||||
let pricingModule: IPricingModuleService
|
|
||||||
let inventoryModule: IInventoryService
|
|
||||||
let stockLocationModule: IStockLocationService
|
|
||||||
let fulfillmentModule: IFulfillmentModuleService
|
|
||||||
let orderModule: IOrderModuleService
|
let orderModule: IOrderModuleService
|
||||||
let remoteLink, remoteQuery
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
appContainer = getContainer()
|
appContainer = getContainer()
|
||||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
|
||||||
regionModuleService = appContainer.resolve(ModuleRegistrationName.REGION)
|
|
||||||
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
|
|
||||||
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
|
|
||||||
inventoryModule = appContainer.resolve(ModuleRegistrationName.INVENTORY)
|
|
||||||
fulfillmentModule = appContainer.resolve(
|
|
||||||
ModuleRegistrationName.FULFILLMENT
|
|
||||||
)
|
|
||||||
remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
|
||||||
remoteQuery = appContainer.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
|
||||||
orderModule = appContainer.resolve(ModuleRegistrationName.ORDER)
|
orderModule = appContainer.resolve(ModuleRegistrationName.ORDER)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -144,12 +112,12 @@ medusaIntegrationTestRunner({
|
|||||||
summary: expect.objectContaining({
|
summary: expect.objectContaining({
|
||||||
// TODO: add all summary fields
|
// TODO: add all summary fields
|
||||||
}),
|
}),
|
||||||
total: 59.79,
|
total: 59.9,
|
||||||
subtotal: 60,
|
subtotal: 60,
|
||||||
tax_total: 0.89,
|
tax_total: 0.9,
|
||||||
discount_total: 1.1,
|
discount_total: 1.1,
|
||||||
discount_tax_total: 0.11,
|
discount_tax_total: 0.1,
|
||||||
original_total: 60.9,
|
original_total: 61,
|
||||||
original_tax_total: 1,
|
original_tax_total: 1,
|
||||||
item_total: 50,
|
item_total: 50,
|
||||||
item_subtotal: 50,
|
item_subtotal: 50,
|
||||||
@@ -157,16 +125,16 @@ medusaIntegrationTestRunner({
|
|||||||
original_item_total: 50,
|
original_item_total: 50,
|
||||||
original_item_subtotal: 50,
|
original_item_subtotal: 50,
|
||||||
original_item_tax_total: 0,
|
original_item_tax_total: 0,
|
||||||
shipping_total: 9.79,
|
shipping_total: 9.9,
|
||||||
shipping_subtotal: 10,
|
shipping_subtotal: 10,
|
||||||
shipping_tax_total: 0.89,
|
shipping_tax_total: 0.9,
|
||||||
original_shipping_tax_total: 1,
|
original_shipping_tax_total: 1,
|
||||||
original_shipping_subtotal: 10,
|
original_shipping_subtotal: 10,
|
||||||
original_shipping_total: 11,
|
original_shipping_total: 11,
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
raw_total: {
|
raw_total: {
|
||||||
value: "59.789999999999999995",
|
value: "59.899999999999999995",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_subtotal: {
|
raw_subtotal: {
|
||||||
@@ -294,6 +262,7 @@ medusaIntegrationTestRunner({
|
|||||||
original_total: 50,
|
original_total: 50,
|
||||||
discount_total: 5e-18,
|
discount_total: 5e-18,
|
||||||
discount_tax_total: 0,
|
discount_tax_total: 0,
|
||||||
|
discount_subtotal: 5e-18,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
original_tax_total: 0,
|
original_tax_total: 0,
|
||||||
refundable_total: 50,
|
refundable_total: 50,
|
||||||
@@ -320,6 +289,10 @@ medusaIntegrationTestRunner({
|
|||||||
value: "5e-18",
|
value: "5e-18",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
|
raw_discount_subtotal: {
|
||||||
|
precision: 20,
|
||||||
|
value: "5e-18",
|
||||||
|
},
|
||||||
raw_discount_tax_total: {
|
raw_discount_tax_total: {
|
||||||
value: "0",
|
value: "0",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
@@ -432,10 +405,10 @@ medusaIntegrationTestRunner({
|
|||||||
deleted_at: null,
|
deleted_at: null,
|
||||||
shipping_method_id: expect.any(String),
|
shipping_method_id: expect.any(String),
|
||||||
rate: 10,
|
rate: 10,
|
||||||
total: 0.89,
|
total: 0.9,
|
||||||
subtotal: 1,
|
subtotal: 1,
|
||||||
raw_total: {
|
raw_total: {
|
||||||
value: "0.89",
|
value: "0.9",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_subtotal: {
|
raw_subtotal: {
|
||||||
@@ -474,18 +447,18 @@ medusaIntegrationTestRunner({
|
|||||||
]),
|
]),
|
||||||
amount: 10,
|
amount: 10,
|
||||||
subtotal: 10,
|
subtotal: 10,
|
||||||
total: 9.79,
|
total: 9.9,
|
||||||
original_total: 11,
|
original_total: 11,
|
||||||
discount_total: 1.1,
|
discount_total: 1.1,
|
||||||
discount_tax_total: 0.11,
|
discount_tax_total: 0.1,
|
||||||
tax_total: 0.89,
|
tax_total: 0.9,
|
||||||
original_tax_total: 1,
|
original_tax_total: 1,
|
||||||
raw_subtotal: {
|
raw_subtotal: {
|
||||||
value: "10",
|
value: "10",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_total: {
|
raw_total: {
|
||||||
value: "9.79",
|
value: "9.9",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_original_total: {
|
raw_original_total: {
|
||||||
@@ -497,11 +470,11 @@ medusaIntegrationTestRunner({
|
|||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_discount_tax_total: {
|
raw_discount_tax_total: {
|
||||||
value: "0.11",
|
value: "0.1",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_tax_total: {
|
raw_tax_total: {
|
||||||
value: "0.89",
|
value: "0.9",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_original_tax_total: {
|
raw_original_tax_total: {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ describe("Total calculation", function () {
|
|||||||
total: 66,
|
total: 66,
|
||||||
original_total: 66,
|
original_total: 66,
|
||||||
discount_total: 0,
|
discount_total: 0,
|
||||||
|
discount_subtotal: 0,
|
||||||
discount_tax_total: 0,
|
discount_tax_total: 0,
|
||||||
tax_total: 6,
|
tax_total: 6,
|
||||||
original_tax_total: 6,
|
original_tax_total: 6,
|
||||||
@@ -60,6 +61,7 @@ describe("Total calculation", function () {
|
|||||||
total: 7.5,
|
total: 7.5,
|
||||||
original_total: 7.5,
|
original_total: 7.5,
|
||||||
discount_total: 0,
|
discount_total: 0,
|
||||||
|
discount_subtotal: 0,
|
||||||
discount_tax_total: 0,
|
discount_tax_total: 0,
|
||||||
tax_total: 2.5,
|
tax_total: 2.5,
|
||||||
original_tax_total: 2.5,
|
original_tax_total: 2.5,
|
||||||
@@ -69,6 +71,7 @@ describe("Total calculation", function () {
|
|||||||
subtotal: 65,
|
subtotal: 65,
|
||||||
tax_total: 8.5,
|
tax_total: 8.5,
|
||||||
discount_total: 0,
|
discount_total: 0,
|
||||||
|
discount_subtotal: 0,
|
||||||
discount_tax_total: 0,
|
discount_tax_total: 0,
|
||||||
item_total: 73.5,
|
item_total: 73.5,
|
||||||
item_subtotal: 65,
|
item_subtotal: 65,
|
||||||
@@ -111,7 +114,7 @@ describe("Total calculation", function () {
|
|||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 10,
|
rate: 10,
|
||||||
total: 8.9,
|
total: 9,
|
||||||
subtotal: 10,
|
subtotal: 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -123,24 +126,26 @@ describe("Total calculation", function () {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
subtotal: 100,
|
subtotal: 100,
|
||||||
total: 97.9,
|
total: 99,
|
||||||
original_total: 110,
|
original_total: 110,
|
||||||
discount_total: 11,
|
discount_total: 11,
|
||||||
discount_tax_total: 1.1,
|
discount_subtotal: 10,
|
||||||
tax_total: 8.9,
|
discount_tax_total: 1,
|
||||||
|
tax_total: 9,
|
||||||
original_tax_total: 10,
|
original_tax_total: 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
total: 97.9,
|
total: 99,
|
||||||
subtotal: 100,
|
subtotal: 100,
|
||||||
tax_total: 8.9,
|
tax_total: 9,
|
||||||
discount_total: 11,
|
discount_total: 11,
|
||||||
discount_tax_total: 1.1,
|
discount_subtotal: 10,
|
||||||
original_total: 99,
|
discount_tax_total: 1,
|
||||||
|
original_total: 110,
|
||||||
original_tax_total: 10,
|
original_tax_total: 10,
|
||||||
item_total: 97.9,
|
item_total: 99,
|
||||||
item_subtotal: 100,
|
item_subtotal: 100,
|
||||||
item_tax_total: 8.9,
|
item_tax_total: 9,
|
||||||
original_item_total: 110,
|
original_item_total: 110,
|
||||||
original_item_subtotal: 100,
|
original_item_subtotal: 100,
|
||||||
original_item_tax_total: 10,
|
original_item_tax_total: 10,
|
||||||
@@ -151,7 +156,7 @@ describe("Total calculation", function () {
|
|||||||
const cartMixed = {
|
const cartMixed = {
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
unit_price: 100,
|
unit_price: 99,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
is_tax_inclusive: true,
|
is_tax_inclusive: true,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
@@ -161,12 +166,12 @@ describe("Total calculation", function () {
|
|||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
{
|
{
|
||||||
amount: 10,
|
amount: 9,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
unit_price: 10,
|
unit_price: 9,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
is_tax_inclusive: false,
|
is_tax_inclusive: false,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
@@ -183,21 +188,21 @@ describe("Total calculation", function () {
|
|||||||
],
|
],
|
||||||
shipping_methods: [
|
shipping_methods: [
|
||||||
{
|
{
|
||||||
amount: 10,
|
amount: 99,
|
||||||
is_tax_inclusive: true,
|
is_tax_inclusive: true,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 5,
|
rate: 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
{
|
{
|
||||||
amount: 2,
|
amount: 9,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
amount: 5,
|
amount: 9,
|
||||||
is_tax_inclusive: false,
|
is_tax_inclusive: false,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
@@ -206,7 +211,7 @@ describe("Total calculation", function () {
|
|||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
{
|
{
|
||||||
amount: 2,
|
amount: 3,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -220,40 +225,41 @@ describe("Total calculation", function () {
|
|||||||
expect(serializedMixed).toEqual({
|
expect(serializedMixed).toEqual({
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
unit_price: 100,
|
unit_price: 99,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
is_tax_inclusive: true,
|
is_tax_inclusive: true,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 10,
|
rate: 10,
|
||||||
total: 8.181818181818182,
|
subtotal: 9,
|
||||||
subtotal: 9.090909090909092,
|
total: 8.1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
{
|
{
|
||||||
amount: 10,
|
amount: 9,
|
||||||
subtotal: 9.090909090909092,
|
subtotal: 8.181818181818182,
|
||||||
total: 10,
|
total: 9,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
subtotal: 90.9090909090909,
|
subtotal: 90,
|
||||||
total: 90,
|
total: 89.1,
|
||||||
original_total: 100,
|
original_total: 99,
|
||||||
discount_total: 10,
|
discount_total: 9,
|
||||||
discount_tax_total: 1,
|
discount_subtotal: 9,
|
||||||
tax_total: 8.181818181818182,
|
discount_tax_total: 0.8181818181818182,
|
||||||
original_tax_total: 9.090909090909092,
|
tax_total: 8.1,
|
||||||
|
original_tax_total: 9,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
unit_price: 10,
|
unit_price: 9,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
is_tax_inclusive: false,
|
is_tax_inclusive: false,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 10,
|
rate: 10,
|
||||||
total: 0.67,
|
total: 0.6,
|
||||||
subtotal: 1,
|
subtotal: 0.9,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
@@ -263,86 +269,90 @@ describe("Total calculation", function () {
|
|||||||
total: 3.3,
|
total: 3.3,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
subtotal: 10,
|
subtotal: 9,
|
||||||
total: 7.37,
|
total: 6.6,
|
||||||
original_total: 11,
|
original_total: 9.9,
|
||||||
discount_total: 3.3,
|
discount_total: 3.3,
|
||||||
discount_tax_total: 0.33,
|
discount_subtotal: 3,
|
||||||
tax_total: 0.67,
|
discount_tax_total: 0.3,
|
||||||
original_tax_total: 1,
|
tax_total: 0.6,
|
||||||
|
original_tax_total: 0.9,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
shipping_methods: [
|
shipping_methods: [
|
||||||
{
|
{
|
||||||
amount: 10,
|
|
||||||
is_tax_inclusive: true,
|
is_tax_inclusive: true,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 5,
|
rate: 10,
|
||||||
total: 0.38095238095238093,
|
subtotal: 9,
|
||||||
subtotal: 0.47619047619047616,
|
total: 8.1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
{
|
{
|
||||||
amount: 2,
|
amount: 9,
|
||||||
subtotal: 1.9047619047619047,
|
subtotal: 8.181818181818182,
|
||||||
total: 2,
|
total: 9,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
subtotal: 9.523809523809524,
|
amount: 99,
|
||||||
total: 8,
|
subtotal: 90,
|
||||||
original_total: 10,
|
total: 89.1,
|
||||||
discount_total: 2,
|
original_total: 99,
|
||||||
discount_tax_total: 0.1,
|
discount_total: 9,
|
||||||
tax_total: 0.38095238095238093,
|
discount_subtotal: 9,
|
||||||
original_tax_total: 0.47619047619047616,
|
discount_tax_total: 0.8181818181818182,
|
||||||
|
tax_total: 8.1,
|
||||||
|
original_tax_total: 9,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
amount: 5,
|
amount: 9,
|
||||||
is_tax_inclusive: false,
|
is_tax_inclusive: false,
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 10,
|
rate: 10,
|
||||||
total: 0.28,
|
total: 0.6,
|
||||||
subtotal: 0.5,
|
subtotal: 0.9,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
{
|
{
|
||||||
amount: 2,
|
amount: 3,
|
||||||
subtotal: 2,
|
subtotal: 3,
|
||||||
total: 2.2,
|
total: 3.3,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
subtotal: 5,
|
subtotal: 9,
|
||||||
total: 3.08,
|
total: 6.6,
|
||||||
original_total: 5.5,
|
original_total: 9.9,
|
||||||
discount_total: 2.2,
|
discount_total: 3.3,
|
||||||
discount_tax_total: 0.22,
|
discount_subtotal: 3,
|
||||||
tax_total: 0.28,
|
discount_tax_total: 0.3,
|
||||||
original_tax_total: 0.5,
|
tax_total: 0.6,
|
||||||
|
original_tax_total: 0.9,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
total: 107.445670995671,
|
total: 191.4,
|
||||||
subtotal: 115.43290043290044,
|
subtotal: 198,
|
||||||
tax_total: 9.512770562770562,
|
tax_total: 17.4,
|
||||||
discount_total: 17.5,
|
discount_total: 24.6,
|
||||||
discount_tax_total: 1.65,
|
discount_subtotal: 24,
|
||||||
original_total: 109.97619047619048,
|
discount_tax_total: 2.2363636363636363,
|
||||||
original_tax_total: 11.067099567099566,
|
original_total: 217.8,
|
||||||
item_total: 97.37,
|
original_tax_total: 19.8,
|
||||||
item_subtotal: 100.9090909090909,
|
item_total: 95.7,
|
||||||
item_tax_total: 8.851818181818182,
|
item_subtotal: 99,
|
||||||
original_item_total: 111,
|
item_tax_total: 8.7,
|
||||||
original_item_subtotal: 100.9090909090909,
|
original_item_total: 108.9,
|
||||||
original_item_tax_total: 10.090909090909092,
|
original_item_subtotal: 99,
|
||||||
shipping_total: 11.08,
|
original_item_tax_total: 9.9,
|
||||||
shipping_subtotal: 14.523809523809524,
|
shipping_total: 95.7,
|
||||||
shipping_tax_total: 0.660952380952381,
|
shipping_subtotal: 99,
|
||||||
original_shipping_tax_total: 0.9761904761904762,
|
shipping_tax_total: 8.7,
|
||||||
original_shipping_subtotal: 14.523809523809524,
|
original_shipping_tax_total: 9.9,
|
||||||
original_shipping_total: 15.5,
|
original_shipping_subtotal: 99,
|
||||||
|
original_shipping_total: 108.9,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -394,6 +404,7 @@ describe("Total calculation", function () {
|
|||||||
expect(serializedWith).toEqual({
|
expect(serializedWith).toEqual({
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
|
discount_subtotal: 0,
|
||||||
unit_price: 50,
|
unit_price: 50,
|
||||||
quantity: 2,
|
quantity: 2,
|
||||||
is_tax_inclusive: true,
|
is_tax_inclusive: true,
|
||||||
@@ -413,6 +424,7 @@ describe("Total calculation", function () {
|
|||||||
original_tax_total: 9.090909090909092,
|
original_tax_total: 9.090909090909092,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
discount_subtotal: 0,
|
||||||
total: 100,
|
total: 100,
|
||||||
subtotal: 90.9090909090909,
|
subtotal: 90.9090909090909,
|
||||||
tax_total: 9.090909090909092,
|
tax_total: 9.090909090909092,
|
||||||
@@ -431,6 +443,7 @@ describe("Total calculation", function () {
|
|||||||
expect(serializedWithout).toEqual({
|
expect(serializedWithout).toEqual({
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
|
discount_subtotal: 0,
|
||||||
unit_price: 50,
|
unit_price: 50,
|
||||||
quantity: 2,
|
quantity: 2,
|
||||||
is_tax_inclusive: false,
|
is_tax_inclusive: false,
|
||||||
@@ -451,6 +464,7 @@ describe("Total calculation", function () {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
total: 110,
|
total: 110,
|
||||||
|
discount_subtotal: 0,
|
||||||
subtotal: 100,
|
subtotal: 100,
|
||||||
tax_total: 10,
|
tax_total: 10,
|
||||||
discount_total: 0,
|
discount_total: 0,
|
||||||
@@ -468,6 +482,7 @@ describe("Total calculation", function () {
|
|||||||
expect(serializedMixed).toEqual({
|
expect(serializedMixed).toEqual({
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
|
discount_subtotal: 0,
|
||||||
unit_price: 50,
|
unit_price: 50,
|
||||||
quantity: 2,
|
quantity: 2,
|
||||||
is_tax_inclusive: true,
|
is_tax_inclusive: true,
|
||||||
@@ -487,6 +502,7 @@ describe("Total calculation", function () {
|
|||||||
original_tax_total: 9.090909090909092,
|
original_tax_total: 9.090909090909092,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
discount_subtotal: 0,
|
||||||
unit_price: 50,
|
unit_price: 50,
|
||||||
quantity: 2,
|
quantity: 2,
|
||||||
is_tax_inclusive: false,
|
is_tax_inclusive: false,
|
||||||
@@ -506,6 +522,7 @@ describe("Total calculation", function () {
|
|||||||
original_tax_total: 10,
|
original_tax_total: 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
discount_subtotal: 0,
|
||||||
total: 210,
|
total: 210,
|
||||||
subtotal: 190.9090909090909,
|
subtotal: 190.9090909090909,
|
||||||
tax_total: 19.09090909090909,
|
tax_total: 19.09090909090909,
|
||||||
@@ -567,23 +584,24 @@ describe("Total calculation", function () {
|
|||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 10,
|
rate: 10,
|
||||||
total: 7.8,
|
total: 8,
|
||||||
subtotal: 10,
|
subtotal: 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
{
|
{
|
||||||
amount: 20,
|
amount: 20,
|
||||||
total: 22,
|
|
||||||
subtotal: 20,
|
subtotal: 20,
|
||||||
|
total: 22,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
subtotal: 100,
|
subtotal: 100,
|
||||||
total: 85.8,
|
total: 88,
|
||||||
original_total: 110,
|
original_total: 110,
|
||||||
discount_total: 22,
|
discount_total: 22,
|
||||||
discount_tax_total: 2.2,
|
discount_subtotal: 20,
|
||||||
tax_total: 7.8,
|
discount_tax_total: 2,
|
||||||
|
tax_total: 8,
|
||||||
original_tax_total: 10,
|
original_tax_total: 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -593,42 +611,44 @@ describe("Total calculation", function () {
|
|||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 10,
|
rate: 10,
|
||||||
total: 2.28,
|
total: 2.3,
|
||||||
subtotal: 2.5,
|
subtotal: 2.5,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
{
|
{
|
||||||
amount: 2,
|
amount: 2,
|
||||||
total: 2.2,
|
|
||||||
subtotal: 2,
|
subtotal: 2,
|
||||||
|
total: 2.2,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
subtotal: 25,
|
subtotal: 25,
|
||||||
total: 25.08,
|
total: 25.3,
|
||||||
original_total: 27.5,
|
original_total: 27.5,
|
||||||
discount_total: 2.2,
|
discount_total: 2.2,
|
||||||
discount_tax_total: 0.22,
|
discount_subtotal: 2,
|
||||||
tax_total: 2.28,
|
discount_tax_total: 0.2,
|
||||||
|
tax_total: 2.3,
|
||||||
original_tax_total: 2.5,
|
original_tax_total: 2.5,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
total: 110.88,
|
total: 113.3,
|
||||||
subtotal: 125,
|
subtotal: 125,
|
||||||
tax_total: 10.08,
|
tax_total: 10.3,
|
||||||
discount_total: 24.2,
|
discount_total: 24.2,
|
||||||
discount_tax_total: 2.42,
|
discount_subtotal: 22,
|
||||||
original_total: 115.8,
|
discount_tax_total: 2.2,
|
||||||
|
original_total: 137.5,
|
||||||
original_tax_total: 12.5,
|
original_tax_total: 12.5,
|
||||||
item_total: 85.8,
|
item_total: 88,
|
||||||
item_subtotal: 100,
|
item_subtotal: 100,
|
||||||
item_tax_total: 7.8,
|
item_tax_total: 8,
|
||||||
original_item_total: 110,
|
original_item_total: 110,
|
||||||
original_item_subtotal: 100,
|
original_item_subtotal: 100,
|
||||||
original_item_tax_total: 10,
|
original_item_tax_total: 10,
|
||||||
shipping_total: 25.08,
|
shipping_total: 25.3,
|
||||||
shipping_subtotal: 25,
|
shipping_subtotal: 25,
|
||||||
shipping_tax_total: 2.28,
|
shipping_tax_total: 2.3,
|
||||||
original_shipping_tax_total: 2.5,
|
original_shipping_tax_total: 2.5,
|
||||||
original_shipping_subtotal: 25,
|
original_shipping_subtotal: 25,
|
||||||
original_shipping_total: 27.5,
|
original_shipping_total: 27.5,
|
||||||
@@ -670,10 +690,18 @@ describe("Total calculation", function () {
|
|||||||
{
|
{
|
||||||
unit_price: 50,
|
unit_price: 50,
|
||||||
quantity: 2,
|
quantity: 2,
|
||||||
|
detail: {
|
||||||
|
fulfilled_quantity: 2,
|
||||||
|
shipped_quantity: 2,
|
||||||
|
return_requested_quantity: 0,
|
||||||
|
return_received_quantity: 1,
|
||||||
|
return_dismissed_quantity: 1,
|
||||||
|
written_off_quantity: 1,
|
||||||
|
},
|
||||||
tax_lines: [
|
tax_lines: [
|
||||||
{
|
{
|
||||||
rate: 10,
|
rate: 10,
|
||||||
total: 7.8,
|
total: 8,
|
||||||
subtotal: 10,
|
subtotal: 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -684,50 +712,44 @@ describe("Total calculation", function () {
|
|||||||
total: 22,
|
total: 22,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
detail: {
|
|
||||||
fulfilled_quantity: 2,
|
|
||||||
return_dismissed_quantity: 1,
|
|
||||||
return_received_quantity: 1,
|
|
||||||
return_requested_quantity: 0,
|
|
||||||
shipped_quantity: 2,
|
|
||||||
written_off_quantity: 1,
|
|
||||||
},
|
|
||||||
subtotal: 100,
|
subtotal: 100,
|
||||||
total: 85.8,
|
total: 88,
|
||||||
original_total: 110,
|
original_total: 110,
|
||||||
discount_total: 22,
|
discount_total: 22,
|
||||||
discount_tax_total: 2.2,
|
discount_subtotal: 20,
|
||||||
tax_total: 7.8,
|
discount_tax_total: 2,
|
||||||
|
tax_total: 8,
|
||||||
original_tax_total: 10,
|
original_tax_total: 10,
|
||||||
fulfilled_total: 85.8,
|
|
||||||
shipped_total: 85.8,
|
|
||||||
return_requested_total: 0,
|
|
||||||
return_received_total: 42.9,
|
|
||||||
return_dismissed_total: 42.9,
|
|
||||||
write_off_total: 42.9,
|
|
||||||
refundable_total: 0,
|
|
||||||
refundable_total_per_unit: 0,
|
refundable_total_per_unit: 0,
|
||||||
|
refundable_total: 0,
|
||||||
|
fulfilled_total: 88,
|
||||||
|
shipped_total: 88,
|
||||||
|
return_requested_total: 0,
|
||||||
|
return_received_total: 44,
|
||||||
|
return_dismissed_total: 44,
|
||||||
|
write_off_total: 44,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
total: 85.8,
|
total: 88,
|
||||||
subtotal: 100,
|
subtotal: 100,
|
||||||
tax_total: 7.8,
|
tax_total: 8,
|
||||||
discount_total: 22,
|
discount_total: 22,
|
||||||
discount_tax_total: 2.2,
|
discount_subtotal: 20,
|
||||||
original_total: 88,
|
discount_tax_total: 2,
|
||||||
|
original_total: 110,
|
||||||
original_tax_total: 10,
|
original_tax_total: 10,
|
||||||
item_total: 85.8,
|
item_total: 88,
|
||||||
item_subtotal: 100,
|
item_subtotal: 100,
|
||||||
item_tax_total: 7.8,
|
item_tax_total: 8,
|
||||||
original_item_total: 110,
|
original_item_total: 110,
|
||||||
original_item_subtotal: 100,
|
original_item_subtotal: 100,
|
||||||
original_item_tax_total: 10,
|
original_item_tax_total: 10,
|
||||||
fulfilled_total: 85.8,
|
fulfilled_total: 88,
|
||||||
shipped_total: 85.8,
|
shipped_total: 88,
|
||||||
return_requested_total: 0,
|
return_requested_total: 0,
|
||||||
return_received_total: 42.9,
|
return_received_total: 44,
|
||||||
return_dismissed_total: 42.9,
|
return_dismissed_total: 44,
|
||||||
write_off_total: 42.9,
|
write_off_total: 44,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -12,31 +12,44 @@ export function calculateAdjustmentTotal({
|
|||||||
includesTax?: boolean
|
includesTax?: boolean
|
||||||
taxRate?: BigNumberInput
|
taxRate?: BigNumberInput
|
||||||
}) {
|
}) {
|
||||||
let total = MathBN.convert(0)
|
// the sum of all adjustment amounts excluding tax
|
||||||
|
let adjustmentsSubtotal = MathBN.convert(0)
|
||||||
|
// the sum of all adjustment amounts including tax
|
||||||
|
let adjustmentsTotal = MathBN.convert(0)
|
||||||
|
// the sum of all taxes on subtotals
|
||||||
|
let adjustmentsTaxTotal = MathBN.convert(0)
|
||||||
|
|
||||||
for (const adj of adjustments) {
|
for (const adj of adjustments) {
|
||||||
if (!isDefined(adj.amount)) {
|
if (!isDefined(adj.amount)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
total = MathBN.add(total, adj.amount)
|
const adjustmentAmount = MathBN.convert(adj.amount)
|
||||||
|
adjustmentsSubtotal = MathBN.add(adjustmentsSubtotal, adjustmentAmount)
|
||||||
|
|
||||||
if (isDefined(taxRate)) {
|
if (isDefined(taxRate)) {
|
||||||
const rate = MathBN.div(taxRate, 100)
|
const adjustmentSubtotal = includesTax
|
||||||
let taxAmount = MathBN.mult(adj.amount, rate)
|
? MathBN.div(adjustmentAmount, MathBN.add(1, taxRate))
|
||||||
|
: adjustmentAmount
|
||||||
|
|
||||||
if (includesTax) {
|
const adjustmentTaxTotal = MathBN.mult(adjustmentSubtotal, taxRate)
|
||||||
taxAmount = MathBN.div(taxAmount, MathBN.add(1, rate))
|
const adjustmentTotal = MathBN.add(adjustmentSubtotal, adjustmentTaxTotal)
|
||||||
|
|
||||||
adj["subtotal"] = new BigNumber(MathBN.sub(adj.amount, taxAmount))
|
adj["subtotal"] = new BigNumber(adjustmentSubtotal)
|
||||||
adj["total"] = new BigNumber(adj.amount)
|
adj["total"] = new BigNumber(adjustmentTotal)
|
||||||
|
|
||||||
|
adjustmentsTotal = MathBN.add(adjustmentsTotal, adjustmentTotal)
|
||||||
|
adjustmentsTaxTotal = MathBN.add(adjustmentsTaxTotal, adjustmentTaxTotal)
|
||||||
} else {
|
} else {
|
||||||
total = MathBN.add(adj.amount, taxAmount)
|
adj["subtotal"] = new BigNumber(adjustmentAmount)
|
||||||
|
adj["adjustmentAmount"] = new BigNumber(adjustmentAmount)
|
||||||
adj["subtotal"] = new BigNumber(adj.amount)
|
adjustmentsTotal = MathBN.add(adjustmentsTotal, adjustmentAmount)
|
||||||
adj["total"] = new BigNumber(total)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return total
|
return {
|
||||||
|
adjustmentsTotal,
|
||||||
|
adjustmentsSubtotal,
|
||||||
|
adjustmentsTaxTotal,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -72,6 +72,7 @@ export function decorateCartTotals(
|
|||||||
let subtotal = MathBN.convert(0)
|
let subtotal = MathBN.convert(0)
|
||||||
|
|
||||||
let discountTotal = MathBN.convert(0)
|
let discountTotal = MathBN.convert(0)
|
||||||
|
let discountSubtotal = MathBN.convert(0)
|
||||||
let discountTaxTotal = MathBN.convert(0)
|
let discountTaxTotal = MathBN.convert(0)
|
||||||
|
|
||||||
let itemsSubtotal = MathBN.convert(0)
|
let itemsSubtotal = MathBN.convert(0)
|
||||||
@@ -96,7 +97,6 @@ export function decorateCartTotals(
|
|||||||
|
|
||||||
const cartItems = items.map((item, index) => {
|
const cartItems = items.map((item, index) => {
|
||||||
const itemTotals = Object.assign(item, itemsTotals[item.id ?? index] ?? {})
|
const itemTotals = Object.assign(item, itemsTotals[item.id ?? index] ?? {})
|
||||||
|
|
||||||
const itemSubtotal = itemTotals.subtotal
|
const itemSubtotal = itemTotals.subtotal
|
||||||
|
|
||||||
const itemTotal = MathBN.convert(itemTotals.total)
|
const itemTotal = MathBN.convert(itemTotals.total)
|
||||||
@@ -106,12 +106,14 @@ export function decorateCartTotals(
|
|||||||
const itemOriginalTaxTotal = MathBN.convert(itemTotals.original_tax_total)
|
const itemOriginalTaxTotal = MathBN.convert(itemTotals.original_tax_total)
|
||||||
|
|
||||||
const itemDiscountTotal = MathBN.convert(itemTotals.discount_total)
|
const itemDiscountTotal = MathBN.convert(itemTotals.discount_total)
|
||||||
|
const itemDiscountSubTotal = MathBN.convert(itemTotals.discount_subtotal)
|
||||||
|
|
||||||
const itemDiscountTaxTotal = MathBN.convert(itemTotals.discount_tax_total)
|
const itemDiscountTaxTotal = MathBN.convert(itemTotals.discount_tax_total)
|
||||||
|
|
||||||
subtotal = MathBN.add(subtotal, itemSubtotal)
|
subtotal = MathBN.add(subtotal, itemSubtotal)
|
||||||
|
|
||||||
discountTotal = MathBN.add(discountTotal, itemDiscountTotal)
|
discountTotal = MathBN.add(discountTotal, itemDiscountTotal)
|
||||||
|
discountSubtotal = MathBN.add(discountSubtotal, itemDiscountSubTotal)
|
||||||
discountTaxTotal = MathBN.add(discountTaxTotal, itemDiscountTaxTotal)
|
discountTaxTotal = MathBN.add(discountTaxTotal, itemDiscountTaxTotal)
|
||||||
|
|
||||||
itemsTotal = MathBN.add(itemsTotal, itemTotal)
|
itemsTotal = MathBN.add(itemsTotal, itemTotal)
|
||||||
@@ -138,47 +140,56 @@ export function decorateCartTotals(
|
|||||||
})
|
})
|
||||||
|
|
||||||
const cartShippingMethods = shippingMethods.map((shippingMethod, index) => {
|
const cartShippingMethods = shippingMethods.map((shippingMethod, index) => {
|
||||||
const methodTotals = Object.assign(
|
const shippingMethodTotals = Object.assign(
|
||||||
shippingMethod,
|
shippingMethod,
|
||||||
shippingMethodsTotals[shippingMethod.id ?? index] ?? {}
|
shippingMethodsTotals[shippingMethod.id ?? index] ?? {}
|
||||||
)
|
)
|
||||||
|
|
||||||
const methodSubtotal = MathBN.convert(methodTotals.subtotal)
|
subtotal = MathBN.add(subtotal, shippingMethodTotals.subtotal)
|
||||||
|
|
||||||
subtotal = MathBN.add(subtotal, methodSubtotal)
|
shippingSubtotal = MathBN.add(
|
||||||
|
shippingSubtotal,
|
||||||
const methodTotal = MathBN.convert(methodTotals.total)
|
shippingMethodTotals.subtotal
|
||||||
const methodOriginalTotal = MathBN.convert(methodTotals.original_total)
|
|
||||||
const methodTaxTotal = MathBN.convert(methodTotals.tax_total)
|
|
||||||
const methodOriginalTaxTotal = MathBN.convert(
|
|
||||||
methodTotals.original_tax_total
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const methodDiscountTotal = MathBN.convert(methodTotals.discount_total)
|
shippingTotal = MathBN.add(shippingTotal, shippingMethodTotals.total)
|
||||||
const methodDiscountTaxTotal = MathBN.convert(
|
|
||||||
methodTotals.discount_tax_total
|
|
||||||
)
|
|
||||||
|
|
||||||
shippingSubtotal = MathBN.add(shippingSubtotal, methodSubtotal)
|
|
||||||
shippingTotal = MathBN.add(shippingTotal, methodTotal)
|
|
||||||
shippingOriginalTotal = MathBN.add(
|
shippingOriginalTotal = MathBN.add(
|
||||||
shippingOriginalTotal,
|
shippingOriginalTotal,
|
||||||
methodOriginalTotal
|
shippingMethodTotals.original_total
|
||||||
)
|
)
|
||||||
|
|
||||||
shippingOriginalSubtotal = MathBN.add(
|
shippingOriginalSubtotal = MathBN.add(
|
||||||
shippingOriginalSubtotal,
|
shippingOriginalSubtotal,
|
||||||
methodSubtotal
|
shippingMethodTotals.subtotal
|
||||||
|
)
|
||||||
|
|
||||||
|
shippingTaxTotal = MathBN.add(
|
||||||
|
shippingTaxTotal,
|
||||||
|
shippingMethodTotals.tax_total
|
||||||
)
|
)
|
||||||
|
|
||||||
shippingTaxTotal = MathBN.add(shippingTaxTotal, methodTaxTotal)
|
|
||||||
shippingOriginalTaxTotal = MathBN.add(
|
shippingOriginalTaxTotal = MathBN.add(
|
||||||
shippingOriginalTaxTotal,
|
shippingOriginalTaxTotal,
|
||||||
methodOriginalTaxTotal
|
shippingMethodTotals.original_tax_total
|
||||||
)
|
)
|
||||||
discountTotal = MathBN.add(discountTotal, methodDiscountTotal)
|
|
||||||
discountTaxTotal = MathBN.add(discountTaxTotal, methodDiscountTaxTotal)
|
|
||||||
|
|
||||||
return methodTotals
|
discountTotal = MathBN.add(
|
||||||
|
discountTotal,
|
||||||
|
shippingMethodTotals.discount_total
|
||||||
|
)
|
||||||
|
|
||||||
|
discountSubtotal = MathBN.add(
|
||||||
|
discountSubtotal,
|
||||||
|
shippingMethodTotals.discount_subtotal
|
||||||
|
)
|
||||||
|
|
||||||
|
discountTaxTotal = MathBN.add(
|
||||||
|
discountTaxTotal,
|
||||||
|
shippingMethodTotals.discount_tax_total
|
||||||
|
)
|
||||||
|
|
||||||
|
return shippingMethodTotals
|
||||||
})
|
})
|
||||||
|
|
||||||
const taxTotal = MathBN.add(itemsTaxTotal, shippingTaxTotal)
|
const taxTotal = MathBN.add(itemsTaxTotal, shippingTaxTotal)
|
||||||
@@ -189,17 +200,11 @@ export function decorateCartTotals(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Gift Card calculations
|
// TODO: Gift Card calculations
|
||||||
|
const originalTotal = MathBN.add(itemsOriginalTotal, shippingOriginalTotal)
|
||||||
|
|
||||||
const originalTempTotal = MathBN.add(
|
|
||||||
itemsOriginalSubtotal,
|
|
||||||
shippingOriginalTotal,
|
|
||||||
originalTaxTotal
|
|
||||||
)
|
|
||||||
const originalTotal = MathBN.sub(originalTempTotal, discountTotal)
|
|
||||||
// TODO: subtract (cart.gift_card_total + cart.gift_card_tax_total)
|
// TODO: subtract (cart.gift_card_total + cart.gift_card_tax_total)
|
||||||
const tempTotal = MathBN.add(subtotal, taxTotal)
|
const tempTotal = MathBN.add(subtotal, taxTotal)
|
||||||
const total = MathBN.sub(tempTotal, discountTotal)
|
const total = MathBN.sub(tempTotal, discountSubtotal)
|
||||||
|
|
||||||
const cart = cartLike as any
|
const cart = cartLike as any
|
||||||
|
|
||||||
cart.total = new BigNumber(total)
|
cart.total = new BigNumber(total)
|
||||||
@@ -207,6 +212,7 @@ export function decorateCartTotals(
|
|||||||
cart.tax_total = new BigNumber(taxTotal)
|
cart.tax_total = new BigNumber(taxTotal)
|
||||||
|
|
||||||
cart.discount_total = new BigNumber(discountTotal)
|
cart.discount_total = new BigNumber(discountTotal)
|
||||||
|
cart.discount_subtotal = new BigNumber(discountSubtotal)
|
||||||
cart.discount_tax_total = new BigNumber(discountTaxTotal)
|
cart.discount_tax_total = new BigNumber(discountTaxTotal)
|
||||||
|
|
||||||
// cart.gift_card_total = giftCardTotal.total || 0
|
// cart.gift_card_total = giftCardTotal.total || 0
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export interface GetItemTotalOutput {
|
|||||||
original_total: BigNumber
|
original_total: BigNumber
|
||||||
|
|
||||||
discount_total: BigNumber
|
discount_total: BigNumber
|
||||||
|
discount_subtotal: BigNumber
|
||||||
discount_tax_total: BigNumber
|
discount_tax_total: BigNumber
|
||||||
|
|
||||||
refundable_total?: BigNumber
|
refundable_total?: BigNumber
|
||||||
@@ -73,7 +74,7 @@ export function getLineItemsTotals(
|
|||||||
|
|
||||||
function setRefundableTotal(
|
function setRefundableTotal(
|
||||||
item: GetItemTotalInput,
|
item: GetItemTotalInput,
|
||||||
discountTotal: BigNumberInput,
|
discountsTotal: BigNumberInput,
|
||||||
totals: GetItemTotalOutput,
|
totals: GetItemTotalOutput,
|
||||||
context: GetLineItemsTotalsContext
|
context: GetLineItemsTotalsContext
|
||||||
) {
|
) {
|
||||||
@@ -84,7 +85,7 @@ function setRefundableTotal(
|
|||||||
itemDetail.return_dismissed_quantity ?? 0
|
itemDetail.return_dismissed_quantity ?? 0
|
||||||
)
|
)
|
||||||
const currentQuantity = MathBN.sub(item.quantity, totalReturnedQuantity)
|
const currentQuantity = MathBN.sub(item.quantity, totalReturnedQuantity)
|
||||||
const discountPerUnit = MathBN.div(discountTotal, item.quantity)
|
const discountPerUnit = MathBN.div(discountsTotal, item.quantity)
|
||||||
|
|
||||||
const refundableSubTotal = MathBN.sub(
|
const refundableSubTotal = MathBN.sub(
|
||||||
MathBN.mult(currentQuantity, item.unit_price),
|
MathBN.mult(currentQuantity, item.unit_price),
|
||||||
@@ -93,7 +94,6 @@ function setRefundableTotal(
|
|||||||
|
|
||||||
const taxTotal = calculateTaxTotal({
|
const taxTotal = calculateTaxTotal({
|
||||||
taxLines: item.tax_lines || [],
|
taxLines: item.tax_lines || [],
|
||||||
includesTax: context.includeTax,
|
|
||||||
taxableAmount: refundableSubTotal,
|
taxableAmount: refundableSubTotal,
|
||||||
})
|
})
|
||||||
const refundableTotal = MathBN.add(refundableSubTotal, taxTotal)
|
const refundableTotal = MathBN.add(refundableSubTotal, taxTotal)
|
||||||
@@ -110,76 +110,67 @@ function getLineItemTotals(
|
|||||||
item: GetItemTotalInput,
|
item: GetItemTotalInput,
|
||||||
context: GetLineItemsTotalsContext
|
context: GetLineItemsTotalsContext
|
||||||
) {
|
) {
|
||||||
const subtotal = MathBN.mult(item.unit_price, item.quantity)
|
const isTaxInclusive = item.is_tax_inclusive ?? context.includeTax
|
||||||
|
const sumTax = MathBN.sum(
|
||||||
const sumTaxRate = MathBN.sum(
|
|
||||||
...((item.tax_lines ?? []).map((taxLine) => taxLine.rate) ?? [])
|
...((item.tax_lines ?? []).map((taxLine) => taxLine.rate) ?? [])
|
||||||
)
|
)
|
||||||
const discountTotal = calculateAdjustmentTotal({
|
|
||||||
|
const sumTaxRate = MathBN.div(sumTax, 100)
|
||||||
|
const totalItemPrice = MathBN.mult(item.unit_price, item.quantity)
|
||||||
|
|
||||||
|
/*
|
||||||
|
If the price is inclusive of tax, we need to remove the taxed amount from the subtotal
|
||||||
|
Original Price = Total Price / (1 + Tax Rate)
|
||||||
|
*/
|
||||||
|
const subtotal = isTaxInclusive
|
||||||
|
? MathBN.div(totalItemPrice, MathBN.add(1, sumTaxRate))
|
||||||
|
: totalItemPrice
|
||||||
|
|
||||||
|
const {
|
||||||
|
adjustmentsTotal: discountsTotal,
|
||||||
|
adjustmentsSubtotal: discountsSubtotal,
|
||||||
|
adjustmentsTaxTotal: discountTaxTotal,
|
||||||
|
} = calculateAdjustmentTotal({
|
||||||
adjustments: item.adjustments || [],
|
adjustments: item.adjustments || [],
|
||||||
includesTax: context.includeTax,
|
includesTax: isTaxInclusive,
|
||||||
taxRate: sumTaxRate,
|
taxRate: sumTaxRate,
|
||||||
})
|
})
|
||||||
const discountTaxTotal = MathBN.mult(
|
|
||||||
discountTotal,
|
|
||||||
MathBN.div(sumTaxRate, 100)
|
|
||||||
)
|
|
||||||
|
|
||||||
const total = MathBN.sub(subtotal, discountTotal)
|
const taxTotal = calculateTaxTotal({
|
||||||
|
taxLines: item.tax_lines || [],
|
||||||
|
taxableAmount: MathBN.sub(subtotal, discountsSubtotal),
|
||||||
|
setTotalField: "total",
|
||||||
|
})
|
||||||
|
|
||||||
|
const originalTaxTotal = calculateTaxTotal({
|
||||||
|
taxLines: item.tax_lines || [],
|
||||||
|
taxableAmount: subtotal,
|
||||||
|
setTotalField: "subtotal",
|
||||||
|
})
|
||||||
|
|
||||||
const totals: GetItemTotalOutput = {
|
const totals: GetItemTotalOutput = {
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
unit_price: item.unit_price,
|
unit_price: item.unit_price,
|
||||||
|
|
||||||
subtotal: new BigNumber(subtotal),
|
subtotal: new BigNumber(subtotal),
|
||||||
total: new BigNumber(total),
|
total: new BigNumber(
|
||||||
|
MathBN.sum(MathBN.sub(subtotal, discountsSubtotal), taxTotal)
|
||||||
|
),
|
||||||
|
|
||||||
original_total: new BigNumber(subtotal),
|
original_total: new BigNumber(
|
||||||
|
isTaxInclusive ? totalItemPrice : MathBN.add(subtotal, originalTaxTotal)
|
||||||
|
),
|
||||||
|
|
||||||
discount_total: new BigNumber(discountTotal),
|
discount_total: new BigNumber(discountsTotal),
|
||||||
|
discount_subtotal: new BigNumber(discountsSubtotal),
|
||||||
discount_tax_total: new BigNumber(discountTaxTotal),
|
discount_tax_total: new BigNumber(discountTaxTotal),
|
||||||
|
|
||||||
tax_total: new BigNumber(0),
|
tax_total: new BigNumber(taxTotal),
|
||||||
original_tax_total: new BigNumber(0),
|
original_tax_total: new BigNumber(originalTaxTotal),
|
||||||
}
|
}
|
||||||
|
|
||||||
const taxableAmountWithDiscount = MathBN.sub(subtotal, discountTotal)
|
|
||||||
const taxableAmount = subtotal
|
|
||||||
|
|
||||||
const taxTotal = calculateTaxTotal({
|
|
||||||
taxLines: item.tax_lines || [],
|
|
||||||
includesTax: context.includeTax,
|
|
||||||
taxableAmount: taxableAmountWithDiscount,
|
|
||||||
setTotalField: "total",
|
|
||||||
})
|
|
||||||
totals.tax_total = new BigNumber(taxTotal)
|
|
||||||
|
|
||||||
if (isDefined(item.detail?.return_requested_quantity)) {
|
if (isDefined(item.detail?.return_requested_quantity)) {
|
||||||
setRefundableTotal(item, discountTotal, totals, context)
|
setRefundableTotal(item, discountsTotal, totals, context)
|
||||||
}
|
|
||||||
|
|
||||||
const originalTaxTotal = calculateTaxTotal({
|
|
||||||
taxLines: item.tax_lines || [],
|
|
||||||
includesTax: context.includeTax,
|
|
||||||
taxableAmount,
|
|
||||||
setTotalField: "subtotal",
|
|
||||||
})
|
|
||||||
totals.original_tax_total = new BigNumber(originalTaxTotal)
|
|
||||||
|
|
||||||
const isTaxInclusive = context.includeTax ?? item.is_tax_inclusive
|
|
||||||
|
|
||||||
if (isTaxInclusive) {
|
|
||||||
totals.subtotal = new BigNumber(
|
|
||||||
MathBN.sub(
|
|
||||||
MathBN.mult(item.unit_price, totals.quantity),
|
|
||||||
originalTaxTotal
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
const newTotal = MathBN.add(total, totals.tax_total)
|
|
||||||
const originalTotal = MathBN.add(subtotal, totals.original_tax_total)
|
|
||||||
totals.total = new BigNumber(newTotal)
|
|
||||||
totals.original_total = new BigNumber(originalTotal)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const div = MathBN.eq(item.quantity, 0) ? 1 : item.quantity
|
const div = MathBN.eq(item.quantity, 0) ? 1 : item.quantity
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export interface GetShippingMethodTotalOutput {
|
|||||||
original_total: BigNumber
|
original_total: BigNumber
|
||||||
|
|
||||||
discount_total: BigNumber
|
discount_total: BigNumber
|
||||||
|
discount_subtotal: BigNumber
|
||||||
discount_tax_total: BigNumber
|
discount_tax_total: BigNumber
|
||||||
|
|
||||||
tax_total: BigNumber
|
tax_total: BigNumber
|
||||||
@@ -35,17 +36,13 @@ export function getShippingMethodsTotals(
|
|||||||
shippingMethods: GetShippingMethodTotalInput[],
|
shippingMethods: GetShippingMethodTotalInput[],
|
||||||
context: GetShippingMethodsTotalsContext
|
context: GetShippingMethodsTotalsContext
|
||||||
): Record<string, GetShippingMethodTotalOutput> {
|
): Record<string, GetShippingMethodTotalOutput> {
|
||||||
const { includeTax } = context
|
|
||||||
|
|
||||||
const shippingMethodsTotals = {}
|
const shippingMethodsTotals = {}
|
||||||
|
|
||||||
let index = 0
|
let index = 0
|
||||||
for (const shippingMethod of shippingMethods) {
|
for (const shippingMethod of shippingMethods) {
|
||||||
shippingMethodsTotals[shippingMethod.id ?? index] = getShippingMethodTotals(
|
shippingMethodsTotals[shippingMethod.id ?? index] = getShippingMethodTotals(
|
||||||
shippingMethod,
|
shippingMethod,
|
||||||
{
|
context
|
||||||
includeTax: includeTax || shippingMethod.is_tax_inclusive,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
index++
|
index++
|
||||||
}
|
}
|
||||||
@@ -57,75 +54,61 @@ export function getShippingMethodTotals(
|
|||||||
shippingMethod: GetShippingMethodTotalInput,
|
shippingMethod: GetShippingMethodTotalInput,
|
||||||
context: GetShippingMethodsTotalsContext
|
context: GetShippingMethodsTotalsContext
|
||||||
) {
|
) {
|
||||||
const amount = MathBN.convert(shippingMethod.amount)
|
const isTaxInclusive = shippingMethod.is_tax_inclusive ?? context.includeTax
|
||||||
const subtotal = MathBN.convert(shippingMethod.amount)
|
|
||||||
|
|
||||||
const sumTaxRate = MathBN.sum(
|
const shippingMethodAmount = MathBN.convert(shippingMethod.amount)
|
||||||
|
const sumTax = MathBN.sum(
|
||||||
...(shippingMethod.tax_lines?.map((taxLine) => taxLine.rate) ?? [])
|
...(shippingMethod.tax_lines?.map((taxLine) => taxLine.rate) ?? [])
|
||||||
)
|
)
|
||||||
|
const sumTaxRate = MathBN.div(sumTax, 100)
|
||||||
|
|
||||||
const discountTotal = calculateAdjustmentTotal({
|
const subtotal = isTaxInclusive
|
||||||
|
? MathBN.div(shippingMethodAmount, MathBN.add(1, sumTaxRate))
|
||||||
|
: shippingMethodAmount
|
||||||
|
|
||||||
|
const {
|
||||||
|
adjustmentsTotal: discountsTotal,
|
||||||
|
adjustmentsSubtotal: discountsSubtotal,
|
||||||
|
adjustmentsTaxTotal: discountsTaxTotal,
|
||||||
|
} = calculateAdjustmentTotal({
|
||||||
adjustments: shippingMethod.adjustments || [],
|
adjustments: shippingMethod.adjustments || [],
|
||||||
includesTax: context.includeTax,
|
includesTax: isTaxInclusive,
|
||||||
taxRate: sumTaxRate,
|
taxRate: sumTaxRate,
|
||||||
})
|
})
|
||||||
const discountTaxTotal = MathBN.mult(
|
|
||||||
discountTotal,
|
|
||||||
MathBN.div(sumTaxRate, 100)
|
|
||||||
)
|
|
||||||
|
|
||||||
const total = MathBN.sub(amount, discountTotal)
|
|
||||||
|
|
||||||
const totals: GetShippingMethodTotalOutput = {
|
|
||||||
amount: new BigNumber(amount),
|
|
||||||
|
|
||||||
subtotal: new BigNumber(subtotal),
|
|
||||||
|
|
||||||
total: new BigNumber(total),
|
|
||||||
original_total: new BigNumber(amount),
|
|
||||||
|
|
||||||
discount_total: new BigNumber(discountTotal),
|
|
||||||
discount_tax_total: new BigNumber(discountTaxTotal),
|
|
||||||
|
|
||||||
tax_total: new BigNumber(0),
|
|
||||||
original_tax_total: new BigNumber(0),
|
|
||||||
}
|
|
||||||
|
|
||||||
const taxLines = shippingMethod.tax_lines || []
|
const taxLines = shippingMethod.tax_lines || []
|
||||||
|
|
||||||
const taxableAmountWithDiscount = MathBN.sub(subtotal, discountTotal)
|
|
||||||
const taxableAmount = subtotal
|
|
||||||
|
|
||||||
const taxTotal = calculateTaxTotal({
|
const taxTotal = calculateTaxTotal({
|
||||||
taxLines,
|
taxLines,
|
||||||
includesTax: context.includeTax,
|
taxableAmount: MathBN.sub(subtotal, discountsSubtotal),
|
||||||
taxableAmount: taxableAmountWithDiscount,
|
|
||||||
setTotalField: "total",
|
setTotalField: "total",
|
||||||
})
|
})
|
||||||
totals.tax_total = new BigNumber(taxTotal)
|
|
||||||
|
|
||||||
const originalTaxTotal = calculateTaxTotal({
|
const originalTaxTotal = calculateTaxTotal({
|
||||||
taxLines,
|
taxLines,
|
||||||
includesTax: context.includeTax,
|
taxableAmount: subtotal,
|
||||||
taxableAmount,
|
|
||||||
setTotalField: "subtotal",
|
setTotalField: "subtotal",
|
||||||
})
|
})
|
||||||
totals.original_tax_total = new BigNumber(originalTaxTotal)
|
|
||||||
|
|
||||||
const isTaxInclusive = context.includeTax ?? shippingMethod.is_tax_inclusive
|
const totals: GetShippingMethodTotalOutput = {
|
||||||
|
amount: new BigNumber(shippingMethodAmount),
|
||||||
|
|
||||||
if (isTaxInclusive) {
|
subtotal: new BigNumber(subtotal),
|
||||||
const subtotal = MathBN.sub(shippingMethod.amount, originalTaxTotal)
|
total: new BigNumber(
|
||||||
totals.subtotal = new BigNumber(subtotal)
|
MathBN.sum(MathBN.sub(subtotal, discountsSubtotal), taxTotal)
|
||||||
} else {
|
),
|
||||||
const originalTotal = MathBN.add(
|
original_total: new BigNumber(
|
||||||
shippingMethod.amount,
|
isTaxInclusive
|
||||||
totals.original_tax_total
|
? shippingMethodAmount
|
||||||
)
|
: MathBN.add(subtotal, originalTaxTotal)
|
||||||
const total = MathBN.add(totals.total, totals.tax_total)
|
),
|
||||||
|
|
||||||
totals.total = new BigNumber(total)
|
discount_total: new BigNumber(discountsTotal),
|
||||||
totals.original_total = new BigNumber(originalTotal)
|
discount_subtotal: new BigNumber(discountsSubtotal),
|
||||||
|
discount_tax_total: new BigNumber(discountsTaxTotal),
|
||||||
|
|
||||||
|
tax_total: new BigNumber(taxTotal),
|
||||||
|
original_tax_total: new BigNumber(originalTaxTotal),
|
||||||
}
|
}
|
||||||
|
|
||||||
return totals
|
return totals
|
||||||
|
|||||||
@@ -4,24 +4,23 @@ import { MathBN } from "../math"
|
|||||||
|
|
||||||
export function calculateTaxTotal({
|
export function calculateTaxTotal({
|
||||||
taxLines,
|
taxLines,
|
||||||
includesTax,
|
|
||||||
taxableAmount,
|
taxableAmount,
|
||||||
setTotalField,
|
setTotalField,
|
||||||
}: {
|
}: {
|
||||||
taxLines: Pick<TaxLineDTO, "rate">[]
|
taxLines: Pick<TaxLineDTO, "rate">[]
|
||||||
includesTax?: boolean
|
|
||||||
taxableAmount: BigNumberInput
|
taxableAmount: BigNumberInput
|
||||||
setTotalField?: string
|
setTotalField?: string
|
||||||
}) {
|
}) {
|
||||||
|
if (MathBN.lte(taxableAmount, 0)) {
|
||||||
|
return MathBN.convert(0)
|
||||||
|
}
|
||||||
|
|
||||||
let taxTotal = MathBN.convert(0)
|
let taxTotal = MathBN.convert(0)
|
||||||
|
|
||||||
for (const taxLine of taxLines) {
|
for (const taxLine of taxLines) {
|
||||||
const rate = MathBN.div(taxLine.rate, 100)
|
const rate = MathBN.div(taxLine.rate, 100)
|
||||||
let taxAmount = MathBN.mult(taxableAmount, rate)
|
let taxAmount = MathBN.mult(taxableAmount, rate)
|
||||||
|
|
||||||
if (includesTax) {
|
|
||||||
taxAmount = MathBN.div(taxAmount, MathBN.add(1, rate))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setTotalField) {
|
if (setTotalField) {
|
||||||
;(taxLine as any)[setTotalField] = new BigNumber(taxAmount)
|
;(taxLine as any)[setTotalField] = new BigNumber(taxAmount)
|
||||||
}
|
}
|
||||||
@@ -41,10 +40,18 @@ export function calculateAmountsWithTax({
|
|||||||
amount: number
|
amount: number
|
||||||
includesTax?: boolean
|
includesTax?: boolean
|
||||||
}) {
|
}) {
|
||||||
|
const sumTaxRate = MathBN.div(
|
||||||
|
MathBN.sum(...((taxLines ?? []).map((taxLine) => taxLine.rate) ?? [])),
|
||||||
|
100
|
||||||
|
)
|
||||||
|
|
||||||
|
const taxableAmount = includesTax
|
||||||
|
? MathBN.div(amount, MathBN.add(1, sumTaxRate))
|
||||||
|
: amount
|
||||||
|
|
||||||
const tax = calculateTaxTotal({
|
const tax = calculateTaxTotal({
|
||||||
taxLines,
|
taxLines,
|
||||||
includesTax,
|
taxableAmount,
|
||||||
taxableAmount: amount,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const defaultStoreCartFields = [
|
|||||||
"subtotal",
|
"subtotal",
|
||||||
"tax_total",
|
"tax_total",
|
||||||
"discount_total",
|
"discount_total",
|
||||||
|
"discount_subtotal",
|
||||||
"discount_tax_total",
|
"discount_tax_total",
|
||||||
"original_total",
|
"original_total",
|
||||||
"original_tax_total",
|
"original_tax_total",
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export const defaultStoreRetrieveOrderFields = [
|
|||||||
"subtotal",
|
"subtotal",
|
||||||
"tax_total",
|
"tax_total",
|
||||||
"discount_total",
|
"discount_total",
|
||||||
|
"discount_subtotal",
|
||||||
"discount_tax_total",
|
"discount_tax_total",
|
||||||
"original_total",
|
"original_total",
|
||||||
"original_tax_total",
|
"original_tax_total",
|
||||||
|
|||||||
+22
-2
@@ -2548,6 +2548,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
|||||||
total: 0,
|
total: 0,
|
||||||
original_total: 100,
|
original_total: 100,
|
||||||
discount_total: 100,
|
discount_total: 100,
|
||||||
|
discount_subtotal: 100,
|
||||||
discount_tax_total: 0,
|
discount_tax_total: 0,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
original_tax_total: 0,
|
original_tax_total: 0,
|
||||||
@@ -2567,6 +2568,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
|||||||
value: "100",
|
value: "100",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
|
raw_discount_subtotal: {
|
||||||
|
value: "100",
|
||||||
|
precision: 20,
|
||||||
|
},
|
||||||
raw_discount_tax_total: {
|
raw_discount_tax_total: {
|
||||||
value: "0",
|
value: "0",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
@@ -2647,6 +2652,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
|||||||
total: 200,
|
total: 200,
|
||||||
original_total: 400,
|
original_total: 400,
|
||||||
discount_total: 200,
|
discount_total: 200,
|
||||||
|
discount_subtotal: 200,
|
||||||
discount_tax_total: 0,
|
discount_tax_total: 0,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
original_tax_total: 0,
|
original_tax_total: 0,
|
||||||
@@ -2666,6 +2672,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
|||||||
value: "200",
|
value: "200",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
|
raw_discount_subtotal: {
|
||||||
|
value: "200",
|
||||||
|
precision: 20,
|
||||||
|
},
|
||||||
raw_discount_tax_total: {
|
raw_discount_tax_total: {
|
||||||
value: "0",
|
value: "0",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
@@ -2704,6 +2714,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
|||||||
total: 10,
|
total: 10,
|
||||||
original_total: 10,
|
original_total: 10,
|
||||||
discount_total: 0,
|
discount_total: 0,
|
||||||
|
discount_subtotal: 0,
|
||||||
discount_tax_total: 0,
|
discount_tax_total: 0,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
original_tax_total: 0,
|
original_tax_total: 0,
|
||||||
@@ -2723,6 +2734,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
|||||||
value: "0",
|
value: "0",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
|
raw_discount_subtotal: {
|
||||||
|
value: "0",
|
||||||
|
precision: 20,
|
||||||
|
},
|
||||||
raw_discount_tax_total: {
|
raw_discount_tax_total: {
|
||||||
value: "0",
|
value: "0",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
@@ -2741,8 +2756,9 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
|||||||
subtotal: 510,
|
subtotal: 510,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
discount_total: 300,
|
discount_total: 300,
|
||||||
|
discount_subtotal: 300,
|
||||||
discount_tax_total: 0,
|
discount_tax_total: 0,
|
||||||
original_total: 210,
|
original_total: 510,
|
||||||
original_tax_total: 0,
|
original_tax_total: 0,
|
||||||
item_total: 200,
|
item_total: 200,
|
||||||
item_subtotal: 500,
|
item_subtotal: 500,
|
||||||
@@ -2772,12 +2788,16 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
|||||||
value: "300",
|
value: "300",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
|
raw_discount_subtotal: {
|
||||||
|
value: "300",
|
||||||
|
precision: 20,
|
||||||
|
},
|
||||||
raw_discount_tax_total: {
|
raw_discount_tax_total: {
|
||||||
value: "0",
|
value: "0",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_original_total: {
|
raw_original_total: {
|
||||||
value: "210",
|
value: "510",
|
||||||
precision: 20,
|
precision: 20,
|
||||||
},
|
},
|
||||||
raw_original_tax_total: {
|
raw_original_tax_total: {
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
expect(created.summary).toEqual(
|
expect(created.summary).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
transaction_total: 68,
|
transaction_total: 68,
|
||||||
pending_difference: -20.21999000999001,
|
pending_difference: -20.10799200799201,
|
||||||
paid_total: 68,
|
paid_total: 68,
|
||||||
refunded_total: 0,
|
refunded_total: 0,
|
||||||
})
|
})
|
||||||
@@ -236,7 +236,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
expect(serializedOrder.summary).toEqual(
|
expect(serializedOrder.summary).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
transaction_total: 48,
|
transaction_total: 48,
|
||||||
pending_difference: -0.21999000999001,
|
pending_difference: -0.10799200799201,
|
||||||
paid_total: 68,
|
paid_total: 68,
|
||||||
refunded_total: 20,
|
refunded_total: 20,
|
||||||
})
|
})
|
||||||
@@ -255,7 +255,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
expect(serializedOrder2.summary).toEqual(
|
expect(serializedOrder2.summary).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
transaction_total: 68,
|
transaction_total: 68,
|
||||||
pending_difference: -20.21999000999001,
|
pending_difference: -20.10799200799201,
|
||||||
paid_total: 68,
|
paid_total: 68,
|
||||||
refunded_total: 0,
|
refunded_total: 0,
|
||||||
})
|
})
|
||||||
@@ -282,7 +282,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
paid_total: 68,
|
paid_total: 68,
|
||||||
refunded_total: 50,
|
refunded_total: 50,
|
||||||
transaction_total: 18,
|
transaction_total: 18,
|
||||||
pending_difference: 29.78000999000999,
|
pending_difference: 29.89200799200799,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -301,7 +301,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
|||||||
paid_total: 68,
|
paid_total: 68,
|
||||||
refunded_total: 70,
|
refunded_total: 70,
|
||||||
transaction_total: -2,
|
transaction_total: -2,
|
||||||
pending_difference: 49.78000999000999,
|
pending_difference: 49.89200799200799,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user