|
| 1 | +/** @odoo-module **/ |
| 2 | + |
| 3 | +import { Component, useRef } from "@odoo/owl"; |
| 4 | +import { usePos } from "@point_of_sale/app/store/pos_hook"; |
| 5 | +import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; |
| 6 | +import { useService } from "@web/core/utils/hooks"; |
| 7 | +import { _t } from "@web/core/l10n/translation"; |
| 8 | +import { Dialog } from "@web/core/dialog/dialog"; |
| 9 | + |
| 10 | +export class AddQuantityDialog extends Component { |
| 11 | + static template = "pos_second_uom.AddQuantityDialog"; |
| 12 | + static components = { Dialog }; |
| 13 | + static props = { |
| 14 | + close: { type: Function }, |
| 15 | + product: { type: Object }, |
| 16 | + orderline: { type: Object }, |
| 17 | + secondUomName: { type: String, optional: true }, |
| 18 | + }; |
| 19 | + |
| 20 | + setup() { |
| 21 | + this.pos = usePos(); |
| 22 | + this.input_qty = useRef("quantityInput"); |
| 23 | + this.uom_ratio = this.computeUomRatio(this.props.product); |
| 24 | + this.dialog = useService("dialog"); |
| 25 | + } |
| 26 | + |
| 27 | + computeUomRatio(product) { |
| 28 | + if (product.uom_id && product.pos_second_uom_id) { |
| 29 | + return product.uom_id.factor / product.pos_second_uom_id.factor; |
| 30 | + } |
| 31 | + return 1; |
| 32 | + } |
| 33 | + |
| 34 | + confirm() { |
| 35 | + const quantity = parseFloat(this.input_qty.el.value); |
| 36 | + if (!quantity || quantity <= 0) { |
| 37 | + this.pos.dialog.add(AlertDialog, { |
| 38 | + title: _t("Error"), |
| 39 | + body: _t("Oops!!!!! Quantity cannot be negative, zero, or empty. Please enter a valid positive number !!"), |
| 40 | + }); |
| 41 | + return; |
| 42 | + } |
| 43 | + this.props.orderline.set_quantity(quantity * this.uom_ratio); |
| 44 | + this.props.close(); |
| 45 | + } |
| 46 | +} |
0 commit comments