Debian Codegraph @

addons/sale/static/src/js/product/product.js

raw symbols SCIP
1
2 import { Component } from "@odoo/owl";
3 import { formatCurrency } from "@web/core/currency";
4 import {
5 ProductTemplateAttributeLine as PTAL
6 } from "../product_template_attribute_line/product_template_attribute_line";
7 import { QuantityButtons } from '../quantity_buttons/quantity_buttons';
8 import { getSelectedCustomPtav } from "../sale_utils";
9 import { _t } from "@web/core/l10n/translation";
10
11 export class Product extends Component {
12 static components = { PTAL, QuantityButtons };
13 static template = "sale.Product";
14 static props = {
15 id: { type: [Number, {value: false}], optional: true },
16 product_tmpl_id: Number,
17 display_name: String,
18 description_sale: [Boolean, String], // backend sends 'false' when there is no description
19 price: Number,
20 quantity: Number,
21 uom: { type: Object, optional: true },
22 available_uoms: { type: Object, optional: true },
23 attribute_lines: Object,
24 optional: Boolean,
25 imageURL: { type: String, optional: true },
26 archived_combinations: Array,
27 exclusions: Object,
28 parent_exclusions: Object,
29 parent_product_tmpl_id: { type: Number, optional: true },
30 price_info: { type: String, optional: true },
31 selectedComboItems: {
32 type: Array,
33 element: Object,
34 shape: {
35 name: String,
36 },
37 optional: true,
38 },
39 };
40
41 //--------------------------------------------------------------------------
42 // Private
43 //--------------------------------------------------------------------------
44
45 /**
46 * Return the price, in the format of the given currency.
47 *
48 * @return {String} - The price, in the format of the given currency.
49 */
50 getFormattedPrice() {
51 return formatCurrency(this.props.price, this.env.currency.id);
52 }
53
54 /**
55 * Check whether this product is the main product.
56 *
57 * @return {Boolean} - Whether this product is the main product.
58 */
59 get isMainProduct() {
60 return this.env.mainProductTmplId === this.props.product_tmpl_id;
61 }
62
63 /**
64 * Return this product's image URL.
65 *
66 * @return {String} This product's image URL.
67 */
68 get imageUrl() {
69 const modelPath = this.props.id
70 ? `product.product/${ this.props.id }`
71 : `product.template/${ this.props.product_tmpl_id }`;
72 return `/web/image/${ modelPath }/image_256`;
73 }
74
75 /**
76 * Check whether the provided PTAL should be shown.
77 *
78 * @return {Boolean} Whether the PTAL should be shown.
79 */
80 shouldShowPtal(ptal) {
81 return this.env.canChangeVariant
82 || ptal.create_variant === 'no_variant'
83 || !!getSelectedCustomPtav(ptal);
84 }
85
86
87 get UoMTitle() {
88 return _t("Packaging");
89 }
90
91 async selectUoM(event) {
92 this.env.setUoM(this.props.product_tmpl_id, parseInt(event.target.value));
93 }
94
95 }