| 1 |
import { Component, useRef } from "@odoo/owl"; |
| 2 |
import { useTimedPress } from "@point_of_sale/app/utils/use_timed_press"; |
| 3 |
import { formatCurrency } from "@web/core/currency"; |
| 4 |
import { TagsList } from "@web/core/tags_list/tags_list"; |
| 5 |
|
| 6 |
export class Orderline extends Component { |
| 7 |
static components = { TagsList }; |
| 8 |
static template = "point_of_sale.Orderline"; |
| 9 |
static props = { |
| 10 |
line: Object, |
| 11 |
class: { type: Object, optional: true }, |
| 12 |
slots: { type: Object, optional: true }, |
| 13 |
showTaxGroupLabels: { type: Boolean, optional: true }, |
| 14 |
showTaxGroup: { type: Boolean, optional: true }, |
| 15 |
mode: { type: String, optional: true }, // display, receipt |
| 16 |
basic_receipt: { type: Boolean, optional: true }, |
| 17 |
onClick: { type: Function, optional: true }, |
| 18 |
onLongPress: { type: Function, optional: true }, |
| 19 |
}; |
| 20 |
static defaultProps = { |
| 21 |
showImage: false, |
| 22 |
showTaxGroupLabels: false, |
| 23 |
showTaxGroup: false, |
| 24 |
mode: "display", |
| 25 |
basic_receipt: false, |
| 26 |
onClick: () => {}, |
| 27 |
onLongPress: () => {}, |
| 28 |
}; |
| 29 |
|
| 30 |
setup() { |
| 31 |
this.root = useRef("root"); |
| 32 |
if (this.props.mode === "display") { |
| 33 |
useTimedPress(this.root, [ |
| 34 |
{ |
| 35 |
type: "release", |
| 36 |
maxDelay: 500, |
| 37 |
callback: (event, duration) => { |
| 38 |
this.props.onClick(event, duration); |
| 39 |
}, |
| 40 |
}, |
| 41 |
{ |
| 42 |
type: "hold", |
| 43 |
delay: 500, |
| 44 |
callback: (event, duration) => { |
| 45 |
this.props.onLongPress(event, duration); |
| 46 |
}, |
| 47 |
}, |
| 48 |
]); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
get line() { |
| 53 |
return this.props.line; |
| 54 |
} |
| 55 |
|
| 56 |
get lineContainerClasses() { |
| 57 |
return { |
| 58 |
selected: this.line.isSelected() && this.props.mode === "display", |
| 59 |
...this.line.getDisplayClasses(), |
| 60 |
...(this.props.class || []), |
| 61 |
"border-start": this.props.mode != "receipt" && this.line.combo_parent_id, |
| 62 |
"orderline-combo fst-italic ms-4": this.line.combo_parent_id, |
| 63 |
"position-relative d-flex align-items-center lh-sm cursor-pointer": true, // Keep all classes here |
| 64 |
}; |
| 65 |
} |
| 66 |
|
| 67 |
get lineClasses() { |
| 68 |
const line = this.line; |
| 69 |
const props = this.props; |
| 70 |
if (line.combo_parent_id) { |
| 71 |
return props.mode === "receipt" ? "px-2" : "p-2"; |
| 72 |
} else { |
| 73 |
if (props.mode === "receipt") { |
| 74 |
return line.combo_line_ids.length > 0 ? "" : "py-1"; |
| 75 |
} else { |
| 76 |
return "p-2"; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
get infoListClasses() { |
| 82 |
const line = this.line; |
| 83 |
const props = this.props; |
| 84 |
if (props.mode === "receipt") { |
| 85 |
return ""; |
| 86 |
} |
| 87 |
if (line.customer_note || line.note || line.discount || line.packLotLines?.length) { |
| 88 |
return "gap-2 mt-1"; |
| 89 |
} |
| 90 |
return ""; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* To avoid to much logic in the template, we compute all values here |
| 95 |
* and use them in the template. |
| 96 |
*/ |
| 97 |
get lineScreenValues() { |
| 98 |
const line = this.line; |
| 99 |
|
| 100 |
// Prevent rendering if the line is not yet linked to an order |
| 101 |
// this can happen during related models connections |
| 102 |
if (!line.order_id) { |
| 103 |
return {}; |
| 104 |
} |
| 105 |
|
| 106 |
const imageUrl = line.product_id?.getImageUrl(); |
| 107 |
const basic = this.props.basic_receipt; |
| 108 |
const unitPart = line.getQuantityStr().unitPart; |
| 109 |
const decimalPart = line.getQuantityStr().decimalPart; |
| 110 |
const decimalPoint = line.getQuantityStr().decimalPoint; |
| 111 |
const discount = line.getDiscountStr(); |
| 112 |
const mode = this.props.mode; |
| 113 |
const attributeStr = line.orderDisplayProductName.attributeString; |
| 114 |
const taxGroup = [ |
| 115 |
...new Set( |
| 116 |
this.line.product_id.taxes_id |
| 117 |
?.map((tax) => tax.tax_group_id.pos_receipt_label) |
| 118 |
.filter((label) => label) |
| 119 |
), |
| 120 |
].join(" "); |
| 121 |
const showPrice = |
| 122 |
!basic && |
| 123 |
line.getQuantityStr() != 1 && |
| 124 |
(mode === "receipt" || (line.price_type !== "original" && !line.combo_parent_id)); |
| 125 |
const priceUnit = `${line.currencyDisplayPriceUnit} / ${ |
| 126 |
line.product_id?.uom_id?.name || "" |
| 127 |
}`; |
| 128 |
return { |
| 129 |
name: mode === "receipt" ? line.full_product_name : line.orderDisplayProductName.name, |
| 130 |
attributeString: mode === "display" && attributeStr && `- ${attributeStr}`, |
| 131 |
internalNote: mode === "display" && line.note && JSON.parse(this.line.note || "[]"), |
| 132 |
isReceipt: mode === "receipt", |
| 133 |
isDisplay: mode === "display", |
| 134 |
discount: !basic && discount && discount !== "0" && !line.combo_parent_id && discount, |
| 135 |
noDiscountPrice: formatCurrency(line.displayPriceNoDiscount, line.currency.id), |
| 136 |
displayPriceUnit: showPrice && line.price !== 0 && priceUnit, |
| 137 |
unitPart: unitPart, |
| 138 |
decimalPart: decimalPart && `${decimalPoint}${decimalPart}`, |
| 139 |
productImage: this.props.showImage && imageUrl, |
| 140 |
taxGroup: this.props.showTaxGroup && taxGroup, |
| 141 |
price: !basic && !line.combo_parent_id && this.line.currencyDisplayPrice, |
| 142 |
lotLines: line.product_id.tracking !== "none" && (line.packLotLines || []), |
| 143 |
}; |
| 144 |
} |
| 145 |
} |