|
| 1 | +import { patch } from "@web/core/utils/patch"; |
| 2 | +import { _t } from "@web/core/l10n/translation"; |
| 3 | +import { useService } from "@web/core/utils/hooks"; |
| 4 | +import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen"; |
| 5 | + |
| 6 | +patch(ProductScreen.prototype, { |
| 7 | + setup() { |
| 8 | + super.setup(...arguments); |
| 9 | + this.orm = useService("orm"); |
| 10 | + }, |
| 11 | + |
| 12 | + async checkOrderPickingStatus(order_id) { |
| 13 | + const result = await this.orm.call("pos.order","check_existing_picking",["pos.order", order_id]); |
| 14 | + return result; |
| 15 | + }, |
| 16 | + |
| 17 | + async sendToPick() { |
| 18 | + const currentOrder = this.pos.get_order(); |
| 19 | + if (!currentOrder) { |
| 20 | + this.notification.add(_t("No active order found!"), { type: "warning" }); |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + const { hasPicking, trackingNumber } = await this.checkOrderPickingStatus(currentOrder.access_token); |
| 25 | + if (hasPicking) { |
| 26 | + this.notification.add(_t(`Order Already Processed. This order already has a picking associated with it. |
| 27 | + Tracking Number : (${trackingNumber})`), { |
| 28 | + type: "danger", |
| 29 | + }) |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + if (!currentOrder.partner_id) { |
| 34 | + this.notification.add(_t(`Select Customer`), { |
| 35 | + type: "warning", |
| 36 | + }) |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + if (!currentOrder.shipping_date) { |
| 41 | + const today = new Date().toISOString().split("T")[0]; |
| 42 | + currentOrder.shipping_date = today; |
| 43 | + } |
| 44 | + |
| 45 | + const syncOrderResult = await this.pos.push_single_order(currentOrder); |
| 46 | + |
| 47 | + await this.orm.call("pos.order", "create_picking_set_shipping", ["pos.order" , syncOrderResult[0].id]); |
| 48 | + |
| 49 | + this.notification.add(_t("Order Sent to Pick"), { |
| 50 | + type: "success", |
| 51 | + }); |
| 52 | + }, |
| 53 | +}); |
0 commit comments