| 1 | import { patch } from "@web/core/utils/patch"; |
| 2 | import { hootPosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions"; |
| 3 | import { models } from "@web/../tests/web_test_helpers"; |
| 4 | |
| 5 | export class SaleOrder extends models.ServerModel { |
| 6 | _name = "sale.order"; |
| 7 | |
| 8 | _load_pos_data_fields() { |
| 9 | return [ |
| 10 | "name", |
| 11 | "state", |
| 12 | "user_id", |
| 13 | "order_line", |
| 14 | "partner_id", |
| 15 | "pricelist_id", |
| 16 | "fiscal_position_id", |
| 17 | "amount_total", |
| 18 | "amount_untaxed", |
| 19 | "amount_unpaid", |
| 20 | "picking_ids", |
| 21 | "partner_shipping_id", |
| 22 | "partner_invoice_id", |
| 23 | "date_order", |
| 24 | "write_date", |
| 25 | ]; |
| 26 | } |
| 27 | |
| 28 | _records = [ |
| 29 | { |
| 30 | id: 1, |
| 31 | name: "S00001", |
| 32 | state: "sale", |
| 33 | order_line: [1, 2], |
| 34 | partner_id: 3, |
| 35 | pricelist_id: 1, |
| 36 | fiscal_position_id: 1, |
| 37 | amount_total: 650, |
| 38 | amount_untaxed: 500, |
| 39 | amount_unpaid: 650, |
| 40 | partner_shipping_id: 3, |
| 41 | partner_invoice_id: 3, |
| 42 | date_order: "2025-07-03 17:04:14", |
| 43 | write_date: "2025-07-03 17:04:14", |
| 44 | }, |
| 45 | ]; |
| 46 | |
| 47 | async load_sale_order_from_pos(id, config_id) { |
| 48 | const order = this.env["sale.order"].find((order) => order.id === id); |
| 49 | const orderLines = this.env["sale.order.line"].filter((line) => |
| 50 | order.order_line.includes(line.id) |
| 51 | ); |
| 52 | const partner = this.env["res.partner"].find((partner) => partner.id === order.partner_id); |
| 53 | const productProducts = this.env["product.product"].filter((product) => |
| 54 | orderLines.map((line) => line.product_id).includes(product.id) |
| 55 | ); |
| 56 | const productTemplates = this.env["product.template"].filter((template) => |
| 57 | productProducts.map((p) => p.product_tmpl_id).includes(template.id) |
| 58 | ); |
| 59 | return { |
| 60 | "sale.order": [order], |
| 61 | "sale.order.line": orderLines, |
| 62 | "res.partner": [partner], |
| 63 | "product.product": productProducts, |
| 64 | "product.template": productTemplates, |
| 65 | }; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | patch(hootPosModels, [...hootPosModels, SaleOrder]); |