Debian Codegraph @

addons/point_of_sale/static/tests/unit/accounting/utils.js

raw
1 const { DateTime } = luxon;
2
3 /**
4 * We use a dedicated method for the price check because we don't want to use
5 * getFilledOrder in case of modification of this method breaks the price test.
6 *
7 * This method is a copy of getFilledOrder from utils.js
8 */
9 export const getFilledOrderForPriceCheck = async (store, data = {}) => {
10 const order = store.addNewOrder(data);
11 // This product1 has a 25% tax with a 100.0 price
12 // This product2 has a 15% + 25% tax with a 1000.0 price
13 const product1 = store.models["product.template"].get(15);
14 const product2 = store.models["product.template"].get(16);
15
16 const date = DateTime.now();
17 order.write_date = date;
18 order.create_date = date;
19 order.pricelist_id = false;
20
21 await store.addLineToOrder(
22 {
23 product_tmpl_id: product1,
24 qty: 1,
25 write_date: date,
26 create_date: date,
27 },
28 order
29 );
30 await store.addLineToOrder(
31 {
32 product_tmpl_id: product2,
33 qty: 1,
34 write_date: date,
35 create_date: date,
36 },
37 order
38 );
39 store.addPendingOrder([order.id]);
40 return order;
41 };
42
43 export const prepareRoundingVals = (store, roundingAmount, roundingMethod, onlyCash = true) => {
44 const config = store.config;
45 const product1 = store.models["product.template"].get(15);
46 const product2 = store.models["product.template"].get(16);
47 const cashPm = store.models["pos.payment.method"].find((pm) => pm.is_cash_count);
48 const cardPm = store.models["pos.payment.method"].find((pm) => !pm.is_cash_count);
49
50 // Changes prices to have a non rounded change
51 product1.list_price = 15.73;
52 product2.list_price = 23.49;
53 product1.product_variant_ids[0].lst_price = 15.73;
54 product2.product_variant_ids[0].lst_price = 23.49;
55
56 config.cash_rounding = true;
57 config.only_round_cash_method = onlyCash;
58 config.rounding_method = store.models["account.cash.rounding"].create({
59 name: "roudning",
60 rounding: roundingAmount,
61 rounding_method: roundingMethod,
62 strategy: "add_invoice_line",
63 });
64
65 return { config, cashPm, cardPm };
66 };