| 1 |
import { test, expect } from "@odoo/hoot"; |
| 2 |
import { expectFormattedPrice, setupPosEnv } from "../utils"; |
| 3 |
import { definePosModels } from "../data/generate_model_definitions"; |
| 4 |
import { getFilledOrderForPriceCheck } from "./utils"; |
| 5 |
|
| 6 |
definePosModels(); |
| 7 |
|
| 8 |
test("Taxes object should contain no discount values", async () => { |
| 9 |
const store = await setupPosEnv(); |
| 10 |
const order = await getFilledOrderForPriceCheck(store); |
| 11 |
order.lines[0].setDiscount(10); |
| 12 |
order.lines[1].setDiscount(20); |
| 13 |
|
| 14 |
const details = order.prices.taxDetails; |
| 15 |
const line1 = order.lines[0].prices; |
| 16 |
const line2 = order.lines[1].prices; |
| 17 |
|
| 18 |
// Order prices |
| 19 |
expect(details.base_amount).toBe(980); // Base amount is 980 = (1000 - 10%) + (100 - 20%) |
| 20 |
expect(details.tax_amount).toBe(257); // Tax amount is 257 = (250 - 10%) + (15 - 20%) + (25 - 20%) |
| 21 |
expect(details.total_amount).toBe(1237); // Total amount is 1237 = 980 + 257 |
| 22 |
|
| 23 |
// Formatted prices |
| 24 |
expectFormattedPrice(order.currencyDisplayPrice, "$ 1,237.00"); |
| 25 |
expectFormattedPrice(order.currencyAmountTaxes, "$ 257.00"); |
| 26 |
expectFormattedPrice(order.lines[0].currencyDisplayPrice, "$ 1,125.00"); |
| 27 |
expectFormattedPrice(order.lines[0].currencyDisplayPriceUnit, "$ 1,125.00"); |
| 28 |
expectFormattedPrice(order.lines[0].currencyDisplayPriceUnitExcl, "$ 900.00"); |
| 29 |
expectFormattedPrice(order.lines[1].currencyDisplayPrice, "$ 112.00"); |
| 30 |
expectFormattedPrice(order.lines[1].currencyDisplayPriceUnit, "$ 112.00"); |
| 31 |
expectFormattedPrice(order.lines[1].currencyDisplayPriceUnitExcl, "$ 80.00"); |
| 32 |
|
| 33 |
// First line (25% on 1000) - no discount |
| 34 |
expect(line1.no_discount_total_included).toBe(1250); |
| 35 |
expect(line1.no_discount_total_excluded).toBe(1000); |
| 36 |
expect(line1.no_discount_taxes_data[0].tax_amount).toBe(250); |
| 37 |
expect(line1.no_discount_taxes_data[0].tax.amount).toBe(25); |
| 38 |
|
| 39 |
// Second line (15% + 25% on 100) - no discount |
| 40 |
expect(line2.no_discount_total_included).toBe(140); |
| 41 |
expect(line2.no_discount_total_excluded).toBe(100); |
| 42 |
expect(line2.no_discount_taxes_data[0].tax_amount).toBe(15); |
| 43 |
expect(line2.no_discount_taxes_data[0].tax.amount).toBe(15); |
| 44 |
expect(line2.no_discount_taxes_data[1].tax_amount).toBe(25); |
| 45 |
expect(line2.no_discount_taxes_data[1].tax.amount).toBe(25); |
| 46 |
}); |