| 1 |
import { formatCurrency } from "@point_of_sale/app/models/utils/currency"; |
| 2 |
import { toRaw } from "@odoo/owl"; |
| 3 |
import { logPosMessage } from "@point_of_sale/app/utils/pretty_console_log"; |
| 4 |
|
| 5 |
const CONSOLE_COLOR = "#FF8269"; |
| 6 |
|
| 7 |
/** |
| 8 |
* This module provides functions to format order and order line data for customer display. |
| 9 |
* The goal is to format data in a way that avoids loading all models in the customer display. |
| 10 |
*/ |
| 11 |
|
| 12 |
export class CustomerDisplayPosAdapter { |
| 13 |
constructor() { |
| 14 |
this.setup(); |
| 15 |
} |
| 16 |
|
| 17 |
setup() { |
| 18 |
this.data = {}; |
| 19 |
this.channel = new BroadcastChannel("UPDATE_CUSTOMER_DISPLAY"); |
| 20 |
} |
| 21 |
|
| 22 |
dispatch(pos) { |
| 23 |
this.channel.postMessage(JSON.parse(JSON.stringify(this.data))); |
| 24 |
pos.data |
| 25 |
.call("pos.config", "update_customer_display", [ |
| 26 |
[pos.config.id], |
| 27 |
this.data, |
| 28 |
localStorage.getItem("device_uuid"), |
| 29 |
]) |
| 30 |
.catch((error) => { |
| 31 |
logPosMessage( |
| 32 |
"CustomerDisplay", |
| 33 |
"dispatch", |
| 34 |
"Failed to update customer display", |
| 35 |
CONSOLE_COLOR, |
| 36 |
[error] |
| 37 |
); |
| 38 |
}); |
| 39 |
} |
| 40 |
|
| 41 |
formatOrderData(order) { |
| 42 |
this.currency = order.currency; |
| 43 |
this.data = { |
| 44 |
finalized: order.finalized, |
| 45 |
general_customer_note: order.general_customer_note, |
| 46 |
amount: order.currencyDisplayPriceIncl, |
| 47 |
subtotal: |
| 48 |
order.config_id.iface_tax_included !== "total" && |
| 49 |
order.prices.taxDetails.has_tax_groups && |
| 50 |
order.currencyDisplayPriceExcl, |
| 51 |
amountTaxes: order.prices.taxDetails.has_tax_groups && order.currencyAmountTaxes, |
| 52 |
change: order.change && formatCurrency(order.change, order.currency), |
| 53 |
paymentLines: order.payment_ids.map((pl) => this.getPaymentData(pl)), |
| 54 |
lines: order.lines.map((l) => this.getOrderlineData(l)), |
| 55 |
qrPaymentData: toRaw(order.getSelectedPaymentline()?.qrPaymentData), |
| 56 |
}; |
| 57 |
} |
| 58 |
|
| 59 |
getOrderlineData(line) { |
| 60 |
return { |
| 61 |
productId: line.product_id.id, |
| 62 |
taxGroupLabels: line.taxGroupLabels, |
| 63 |
discount: line.getDiscountStr(), |
| 64 |
customerNote: line.getCustomerNote() || "", |
| 65 |
internalNote: line.getNote() || "[]", |
| 66 |
productName: line.getFullProductName(), |
| 67 |
price: line.currencyDisplayPrice, |
| 68 |
qty: line.getQuantityStr().qtyStr, |
| 69 |
unit: line.product_id.uom_id ? line.product_id.uom_id.name : "", |
| 70 |
unitPrice: line.currencyDisplayPriceUnit, |
| 71 |
packLotLines: line.packLotLines, |
| 72 |
comboParent: line.combo_parent_id?.getFullProductName?.() || "", |
| 73 |
price_without_discount: formatCurrency(line.displayPriceNoDiscount, line.currency), |
| 74 |
isSelected: line.isSelected(), |
| 75 |
}; |
| 76 |
} |
| 77 |
|
| 78 |
getPaymentData(payment) { |
| 79 |
return { |
| 80 |
name: payment.payment_method_id.name, |
| 81 |
amount: formatCurrency(payment.amount, this.currency), |
| 82 |
}; |
| 83 |
} |
| 84 |
} |