Debian Codegraph @

addons/point_of_sale/static/src/app/models/product_product.js

raw
1 import { registry } from "@web/core/registry";
2 import { Base } from "./related_models";
3 import { normalize } from "@web/core/l10n/utils";
4
5 // When adding a method to this class, please pay attention to naming.
6 // As in the backend, when trying to access taxes_id on product.product,
7 // taxes_id will be taken from the template.
8
9 // This means that if you declare a method that exists in the product.template
10 // class, it will override this path.
11 export class ProductProduct extends Base {
12 static pythonModel = "product.product";
13
14 getImageUrl() {
15 return `/web/image?model=product.product&field=image_128&id=${this.id}&unique=${this.write_date}`;
16 }
17
18 get searchString() {
19 const fields = ["display_name", "barcode", "default_code"];
20 const raw = fields
21 .map((field) => this[field] || "")
22 .filter(Boolean)
23 .join(" ");
24 return normalize(raw);
25 }
26 }
27
28 const ProductProductTemplateProxy = new Proxy(ProductProduct, {
29 construct(target, args) {
30 const instance = new target(...args);
31 return new Proxy(instance, {
32 get(target, prop) {
33 const val = Reflect.get(target, prop);
34
35 if (val || target.model.fields[prop] || typeof prop === "symbol") {
36 return val;
37 }
38
39 return target?.product_tmpl_id?.[prop];
40 },
41 });
42 },
43 });
44
45 registry
46 .category("pos_available_models")
47 .add(ProductProduct.pythonModel, ProductProductTemplateProxy);