Debian Codegraph @

addons/pos_sale/static/src/app/models/pos_order_line.js

raw symbols SCIP
1 import { PosOrderline } from "@point_of_sale/app/models/pos_order_line";
2 import { formatCurrency } from "@point_of_sale/app/models/utils/currency";
3 import { patch } from "@web/core/utils/patch";
4
5 patch(PosOrderline.prototype, {
6 setup(_defaultObj) {
7 super.setup(...arguments);
8 // It is possible that this orderline is initialized using server data,
9 // meaning, it is loaded from localStorage or from server. This means
10 // that some fields has already been assigned. Therefore, we only set the options
11 // when the original value is falsy.
12 if (this.sale_order_origin_id?.shipping_date) {
13 this.order_id.setShippingDate(this.sale_order_origin_id.shipping_date);
14 }
15 },
16 get saleDetails() {
17 let down_payment_details = [];
18
19 // FIXME: This is a hack to handle the case where the down_payment_details is a stringified JSON.
20 try {
21 down_payment_details = JSON.parse(this.down_payment_details);
22 } catch {
23 down_payment_details = this.down_payment_details;
24 }
25 return down_payment_details?.map?.((detail) => ({
26 product_uom_qty: detail.product_uom_qty,
27 product_name: detail.product_name,
28 total: formatCurrency(detail.total, this.currency),
29 }));
30 },
31 /**
32 * Set quantity based on the give sale order line.
33 * @param {'sale.order.line'} saleOrderLine
34 */
35 async setQuantityFromSOL(saleOrderLine) {
36 if (
37 this.product_id.type === "service" &&
38 !["sent", "draft"].includes(this.sale_order_origin_id.state)
39 ) {
40 this.setQuantity(saleOrderLine.qty_to_invoice);
41 } else {
42 this.setQuantity(
43 saleOrderLine.product_uom_qty -
44 Math.max(saleOrderLine.qty_delivered, saleOrderLine.qty_invoiced)
45 );
46 }
47 },
48 });