mirror of
https://github.com/bringout/oca-ocb-pos.git
synced 2026-04-24 08:42:08 +02:00
19.0 vanilla
This commit is contained in:
parent
6e54c1af6c
commit
3ca647e428
1087 changed files with 132065 additions and 108499 deletions
|
|
@ -0,0 +1,71 @@
|
|||
import { animationFrame, expect, test } from "@odoo/hoot";
|
||||
import { mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { setupPosEnv, expectFormattedPrice } from "@point_of_sale/../tests/unit/utils";
|
||||
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("getNumpadButtons", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const order = store.addNewOrder();
|
||||
const product1 = store.models["product.template"].get(5);
|
||||
await store.addLineToOrder(
|
||||
{
|
||||
product_tmpl_id: product1,
|
||||
qty: 1,
|
||||
},
|
||||
order
|
||||
);
|
||||
const productScreen = await mountWithCleanup(ProductScreen, {
|
||||
props: { orderUuid: order.uuid },
|
||||
});
|
||||
await store.applyDiscount(10);
|
||||
await animationFrame();
|
||||
const receivedButtonsDisableStatue = productScreen
|
||||
.getNumpadButtons()
|
||||
.filter((button) => ["quantity", "discount"].includes(button.value))
|
||||
.map((button) => button.disabled);
|
||||
expect(Math.abs(order.discountLines[0].priceIncl).toString()).toBe(
|
||||
(order.lines[0].priceIncl * 0.1).toPrecision(2)
|
||||
);
|
||||
|
||||
expect(receivedButtonsDisableStatue).toEqual([true, true]);
|
||||
|
||||
await productScreen.addProductToOrder(product1);
|
||||
// Animation frame doesn't work here since the debounced function used to recompute
|
||||
// discount is using eventListener, so we use setTimeout instead.
|
||||
setTimeout(() => {
|
||||
expect(Math.abs(order.discountLines[0].priceIncl).toString()).toBe(
|
||||
(order.lines[0].priceIncl * 0.1).toPrecision(2)
|
||||
);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
test("addProductToOrder reapplies the global discount", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const order = store.addNewOrder();
|
||||
const product = store.models["product.template"].get(5);
|
||||
const productScreen = await mountWithCleanup(ProductScreen, {
|
||||
props: { orderUuid: order.uuid },
|
||||
});
|
||||
|
||||
await productScreen.addProductToOrder(product);
|
||||
expectFormattedPrice(productScreen.total, "$ 3.45");
|
||||
expect(order.priceIncl).toBe(3.45);
|
||||
expect(order.priceExcl).toBe(3);
|
||||
expect(order.amountTaxes).toBe(0.45);
|
||||
|
||||
await store.applyDiscount(10);
|
||||
expectFormattedPrice(productScreen.total, "$ 3.10");
|
||||
expect(order.priceIncl).toBe(3.1);
|
||||
expect(order.priceExcl).toBe(2.7);
|
||||
expect(order.amountTaxes).toBe(0.4);
|
||||
|
||||
await productScreen.addProductToOrder(product);
|
||||
await animationFrame();
|
||||
expectFormattedPrice(productScreen.total, "$ 6.21");
|
||||
expect(order.priceIncl).toBeCloseTo(6.21, { margin: 1e-12 });
|
||||
expect(order.priceExcl).toBe(5.4);
|
||||
expect(order.amountTaxes).toBe(0.81);
|
||||
});
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import { PosConfig } from "@point_of_sale/../tests/unit/data/pos_config.data";
|
||||
|
||||
PosConfig._records = PosConfig._records.map((record) => ({
|
||||
...record,
|
||||
module_pos_discount: true,
|
||||
discount_product_id: 151,
|
||||
}));
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { ProductProduct } from "@point_of_sale/../tests/unit/data/product_product.data";
|
||||
|
||||
ProductProduct._records = [
|
||||
...ProductProduct._records,
|
||||
{
|
||||
id: 151,
|
||||
product_tmpl_id: 151,
|
||||
lst_price: 1,
|
||||
standard_price: 0,
|
||||
display_name: "Discount",
|
||||
product_tag_ids: [],
|
||||
barcode: false,
|
||||
default_code: false,
|
||||
product_template_attribute_value_ids: [],
|
||||
product_template_variant_value_ids: [],
|
||||
},
|
||||
];
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import { ProductTemplate } from "@point_of_sale/../tests/unit/data/product_template.data";
|
||||
|
||||
ProductTemplate._records = [
|
||||
...ProductTemplate._records,
|
||||
{
|
||||
id: 151,
|
||||
name: "Discount",
|
||||
display_name: "Discount",
|
||||
list_price: 0,
|
||||
standard_price: 0,
|
||||
type: "consu",
|
||||
service_tracking: "none",
|
||||
pos_categ_ids: [1],
|
||||
categ_id: false,
|
||||
uom_id: 1,
|
||||
available_in_pos: true,
|
||||
active: true,
|
||||
},
|
||||
];
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import { animationFrame, expect, test } from "@odoo/hoot";
|
||||
import { setupPosEnv, getFilledOrder } from "@point_of_sale/../tests/unit/utils";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("isDiscountLine", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const order = store.addNewOrder();
|
||||
const product1 = store.models["product.template"].get(5);
|
||||
await store.addLineToOrder(
|
||||
{
|
||||
product_tmpl_id: product1,
|
||||
qty: 1,
|
||||
},
|
||||
order
|
||||
);
|
||||
await store.applyDiscount(10);
|
||||
await animationFrame();
|
||||
const orderline = order.getSelectedOrderline();
|
||||
expect(Math.abs(orderline.price_subtotal_incl).toString()).toBe(
|
||||
((order.amount_total + order.amount_tax) * 0.1).toPrecision(2)
|
||||
);
|
||||
expect(orderline.isDiscountLine).toBe(true);
|
||||
});
|
||||
|
||||
test("Test taxes after fiscal position with discount product (should not change)", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const order = await getFilledOrder(store);
|
||||
order.fiscal_position_id = store.models["account.fiscal.position"].get(1);
|
||||
await store.applyDiscount(20);
|
||||
await animationFrame();
|
||||
const discountLine = order.discountLines[0];
|
||||
const lineValues = discountLine.prepareBaseLineForTaxesComputationExtraValues();
|
||||
const recomputedTaxes = order.fiscal_position_id.getTaxesAfterFiscalPosition(
|
||||
discountLine.product_id.taxes_id
|
||||
);
|
||||
expect(recomputedTaxes).not.toBe(lineValues.tax_ids);
|
||||
});
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
import { test, describe, expect } from "@odoo/hoot";
|
||||
import { patchWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
definePosModels();
|
||||
|
||||
describe("PoS Discount", () => {
|
||||
test("changing fiscal positions reapplies the global discount", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const order = store.addNewOrder();
|
||||
|
||||
const product = store.models["product.template"].get(5);
|
||||
|
||||
await store.addLineToOrder({ product_tmpl_id: product, qty: 10 }, order);
|
||||
expect(order.priceIncl).toBe(34.5);
|
||||
expect(order.priceExcl).toBe(30);
|
||||
expect(order.amountTaxes).toBe(4.5);
|
||||
|
||||
await store.applyDiscount(10);
|
||||
expect(order.priceIncl).toBe(31.05);
|
||||
expect(order.priceExcl).toBe(27);
|
||||
expect(order.amountTaxes).toBe(4.05);
|
||||
|
||||
let [productLine, discountLine] = order.lines;
|
||||
expect(productLine.priceIncl).toBe(34.5);
|
||||
expect(discountLine.priceIncl).toBe(-3.45);
|
||||
|
||||
let resolveReapplyDiscount = null;
|
||||
const reapplyDiscountPromise = new Promise((resolve) => {
|
||||
resolveReapplyDiscount = resolve;
|
||||
});
|
||||
|
||||
patchWithCleanup(store, {
|
||||
async debouncedDiscount() {
|
||||
await super.applyDiscount(...arguments);
|
||||
resolveReapplyDiscount();
|
||||
},
|
||||
});
|
||||
|
||||
const nonTaxFP = store.models["account.fiscal.position"].get(2);
|
||||
order.fiscal_position_id = nonTaxFP;
|
||||
|
||||
await reapplyDiscountPromise;
|
||||
expect(order.priceIncl).toBe(27);
|
||||
expect(order.priceExcl).toBe(27);
|
||||
expect(order.amountTaxes).toBe(0);
|
||||
|
||||
[productLine, discountLine] = order.lines;
|
||||
expect(productLine.priceIncl).toBe(30);
|
||||
expect(discountLine.priceIncl).toBe(-3);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue