| 1 |
import { test, expect, describe } from "@odoo/hoot"; |
| 2 |
import { setupPosEnv, getFilledOrder } from "@point_of_sale/../tests/unit/utils"; |
| 3 |
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions"; |
| 4 |
|
| 5 |
definePosModels(); |
| 6 |
|
| 7 |
describe("saleDetails", () => { |
| 8 |
test("down payment details as array", async () => { |
| 9 |
const store = await setupPosEnv(); |
| 10 |
const order = store.addNewOrder(); |
| 11 |
|
| 12 |
const productDownPayment = store.models["product.template"].get(105); |
| 13 |
const line = await store.addLineToOrder( |
| 14 |
{ |
| 15 |
product_tmpl_id: productDownPayment, |
| 16 |
down_payment_details: [ |
| 17 |
{ |
| 18 |
product_name: "Product 1", |
| 19 |
product_uom_qty: 2, |
| 20 |
total: 100, |
| 21 |
}, |
| 22 |
{ |
| 23 |
product_name: "Product 2", |
| 24 |
product_uom_qty: 1, |
| 25 |
total: 50, |
| 26 |
}, |
| 27 |
], |
| 28 |
qty: 1, |
| 29 |
}, |
| 30 |
order |
| 31 |
); |
| 32 |
|
| 33 |
const saleDetails = line.saleDetails; |
| 34 |
expect(saleDetails).toEqual([ |
| 35 |
{ |
| 36 |
product_uom_qty: 2, |
| 37 |
product_name: "Product 1", |
| 38 |
total: "$\u00a0100.00", |
| 39 |
}, |
| 40 |
{ |
| 41 |
product_uom_qty: 1, |
| 42 |
product_name: "Product 2", |
| 43 |
total: "$\u00a050.00", |
| 44 |
}, |
| 45 |
]); |
| 46 |
}); |
| 47 |
|
| 48 |
test("down payment details as stringified JSON", async () => { |
| 49 |
const store = await setupPosEnv(); |
| 50 |
const order = store.addNewOrder(); |
| 51 |
|
| 52 |
const productDownPayment = store.models["product.template"].get(105); |
| 53 |
const line = await store.addLineToOrder( |
| 54 |
{ |
| 55 |
product_tmpl_id: productDownPayment, |
| 56 |
down_payment_details: JSON.stringify([ |
| 57 |
{ |
| 58 |
product_name: "Product 1", |
| 59 |
product_uom_qty: 2, |
| 60 |
total: 100, |
| 61 |
}, |
| 62 |
{ |
| 63 |
product_name: "Product 2", |
| 64 |
product_uom_qty: 1, |
| 65 |
total: 50, |
| 66 |
}, |
| 67 |
]), |
| 68 |
qty: 1, |
| 69 |
}, |
| 70 |
order |
| 71 |
); |
| 72 |
|
| 73 |
const saleDetails = line.saleDetails; |
| 74 |
expect(saleDetails).toEqual([ |
| 75 |
{ |
| 76 |
product_uom_qty: 2, |
| 77 |
product_name: "Product 1", |
| 78 |
total: "$\u00a0100.00", |
| 79 |
}, |
| 80 |
{ |
| 81 |
product_uom_qty: 1, |
| 82 |
product_name: "Product 2", |
| 83 |
total: "$\u00a050.00", |
| 84 |
}, |
| 85 |
]); |
| 86 |
}); |
| 87 |
}); |
| 88 |
|
| 89 |
describe("setQuantityFromSOL", () => { |
| 90 |
test("service product, state != sent/draft → qty_to_invoice", async () => { |
| 91 |
const store = await setupPosEnv(); |
| 92 |
const order = await getFilledOrder(store); |
| 93 |
const line = order.lines[0]; |
| 94 |
line.product_id.type = "service"; |
| 95 |
line.sale_order_origin_id = { state: "sale" }; |
| 96 |
|
| 97 |
const saleOrderLine = { qty_to_invoice: 2 }; |
| 98 |
|
| 99 |
await line.setQuantityFromSOL(saleOrderLine); |
| 100 |
expect(line.qty).toBe(2); |
| 101 |
}); |
| 102 |
|
| 103 |
test("non-service product → qty = uom_qty - max(delivered, invoiced)", async () => { |
| 104 |
const store = await setupPosEnv(); |
| 105 |
const order = await getFilledOrder(store); |
| 106 |
const line = order.lines[0]; |
| 107 |
line.product_id.type = "consu"; |
| 108 |
|
| 109 |
const saleOrderLine = { |
| 110 |
product_uom_qty: 8, |
| 111 |
qty_delivered: 1, |
| 112 |
qty_invoiced: 2, |
| 113 |
}; |
| 114 |
|
| 115 |
await line.setQuantityFromSOL(saleOrderLine); |
| 116 |
expect(line.qty).toBe(6); |
| 117 |
}); |
| 118 |
}); |