Debian Codegraph @

addons/uom/static/src/components/many2one_uom/many2one_uom_field.js

raw symbols SCIP
1 import { Component } from "@odoo/owl";
2 import { _t } from "@web/core/l10n/translation";
3 import { registry } from "@web/core/registry";
4 import { computeM2OProps, Many2One } from "@web/views/fields/many2one/many2one";
5 import {
6 buildM2OFieldDescription,
7 extractM2OFieldProps,
8 m2oSupportedOptions,
9 Many2OneField,
10 } from "@web/views/fields/many2one/many2one_field";
11 import { getProductRelatedModel, Many2XUomTagsAutocomplete } from "../many2x_uom_tags/many2x_uom_tags";
12
13 // @todo: this extension will be removed in the future
14 // when the autocomplete source generation come from a hook.
15 class UomMany2One extends Many2One {
16 static components = {
17 ...super.components,
18 Many2XAutocomplete: Many2XUomTagsAutocomplete,
19 };
20 static props = {
21 ...super.props,
22 productModel: { type: String, optional: true },
23 productId: { type: Number, optional: true },
24 productQuantity: { type: Number, optional: true },
25 };
26
27 get many2XAutocompleteProps() {
28 return {
29 ...super.many2XAutocompleteProps,
30 productModel: this.props.productModel,
31 productId: this.props.productId,
32 productQuantity: this.props.productQuantity,
33 };
34 }
35 }
36
37 export class Many2OneUomField extends Component {
38 static template = "uom.Many2OneUomField";
39 static components = { UomMany2One };
40 static props = {
41 ...Many2OneField.props,
42 productField: { type: String, optional: true },
43 quantityField: { type: String, optional: true },
44 };
45 static defaultProps = {
46 ...Many2OneField.defaultProps,
47 productField: "product_id",
48 quantityField: "product_uom_qty",
49 };
50
51 get m2oProps() {
52 const productModel = getProductRelatedModel.call(this);
53 let productId = this.props.record.data[this.props.productField]?.id || 0;
54 if (["product.template", "product.product"].includes(this.props.record.resModel)) {
55 productId = this.props.record.resId || 0;
56 }
57 return {
58 ...computeM2OProps(this.props),
59 productModel,
60 productId,
61 productQuantity: this.props.record.data[this.props.quantityField],
62 // specification: {
63 // name: {},
64 // relative_factor: {},
65 // relative_uom_id: {
66 // fields: {
67 // display_name: {},
68 // },
69 // },
70 // },
71 };
72 }
73
74 getLabel(record) {
75 return record.name ? record.name.split("\n")[0] : _t("Unnamed");
76 }
77 }
78
79 registry.category("fields").add("many2one_uom", {
80 ...buildM2OFieldDescription(Many2OneUomField),
81 additionalClasses: ["o_field_many2one"],
82 extractProps(staticInfo, dynamicInfo) {
83 return {
84 ...extractM2OFieldProps(staticInfo, dynamicInfo),
85 productField: staticInfo.options.product_field,
86 quantityField: staticInfo.options.quantity_field,
87 };
88 },
89 supportedOptions: [
90 ...m2oSupportedOptions,
91 {
92 label: _t("Product Field Name"),
93 name: "product_field",
94 type: "field",
95 availableTypes: ["many2one"],
96 },
97 {
98 label: _t("Quantity Field Name"),
99 name: "quantity_field",
100 type: "field",
101 availableTypes: ["many2one"],
102 },
103 ],
104 });