diff --git a/addons/delivery/models/product_packaging.py b/addons/delivery/models/product_packaging.py index 7e98ebf7cff..939a6dd0bdf 100644 --- a/addons/delivery/models/product_packaging.py +++ b/addons/delivery/models/product_packaging.py @@ -7,12 +7,21 @@ from odoo import models, fields, api class ProductPackaging(models.Model): _inherit = 'product.packaging' + + def _get_default_length_uom(self): + return self.env['product.template']._get_length_uom_name_from_ir_config_parameter() + + def _get_default_weight_uom(self): + return self.env['product.template']._get_weight_uom_name_from_ir_config_parameter() + height = fields.Integer('Height') width = fields.Integer('Width') packaging_length = fields.Integer('Length') max_weight = fields.Float('Max Weight', help='Maximum weight shippable in this packaging') shipper_package_code = fields.Char('Package Code') package_carrier_type = fields.Selection([('none', 'No carrier integration')], string='Carrier', default='none') + weight_uom_name = fields.Char(string='Weight unit of measure label', compute='_compute_weight_uom_name', default=_get_default_weight_uom) + length_uom_name = fields.Char(string='Length unit of measure label', compute='_compute_length_uom_name', default=_get_default_length_uom) _sql_constraints = [ ('positive_height', 'CHECK(height>=0)', 'Height must be positive'), @@ -28,3 +37,12 @@ class ProductPackaging(models.Model): self.shipper_package_code = carrier_id._get_default_custom_package_code() else: self.shipper_package_code = False + + + def _compute_length_uom_name(self): + for packaging in self: + packaging.length_uom_name = self.env['product.template']._get_length_uom_name_from_ir_config_parameter() + + def _compute_weight_uom_name(self): + for packaging in self: + packaging.weight_uom_name = self.env['product.template']._get_weight_uom_name_from_ir_config_parameter() diff --git a/addons/delivery/views/product_packaging_view.xml b/addons/delivery/views/product_packaging_view.xml index 612d4f9fd99..0d3baff2194 100644 --- a/addons/delivery/views/product_packaging_view.xml +++ b/addons/delivery/views/product_packaging_view.xml @@ -13,13 +13,33 @@ + - - - - + + + diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 8e399829112..aed3e0dc752 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -275,30 +275,53 @@ class ProductTemplate(models.Model): by adding an ir.config_parameter record with "product.product_weight_in_lbs" as key and "1" as value. """ - get_param = self.env['ir.config_parameter'].sudo().get_param - product_weight_in_lbs_param = get_param('product.weight_in_lbs') + product_weight_in_lbs_param = self.env['ir.config_parameter'].sudo().get_param('product.weight_in_lbs') if product_weight_in_lbs_param == '1': return self.env.ref('uom.product_uom_lb') else: return self.env.ref('uom.product_uom_kgm') @api.model - def _get_weight_uom_name_from_ir_config_parameter(self): - return self._get_weight_uom_id_from_ir_config_parameter().display_name - - def _compute_weight_uom_name(self): - for template in self: - template.weight_uom_name = self._get_weight_uom_name_from_ir_config_parameter() + def _get_length_uom_id_from_ir_config_parameter(self): + """ Get the unit of measure to interpret the `length`, 'width', 'height' field. + By default, we considerer that length are expressed in meters. Users can configure + to express them in feet by adding an ir.config_parameter record with "product.volume_in_cubic_feet" + as key and "1" as value. + """ + product_length_in_feet_param = self.env['ir.config_parameter'].sudo().get_param('product.volume_in_cubic_feet') + if product_length_in_feet_param == '1': + return self.env.ref('uom.product_uom_foot') + else: + return self.env.ref('uom.product_uom_meter') @api.model - def _get_volume_uom_name_from_ir_config_parameter(self): + def _get_volume_uom_id_from_ir_config_parameter(self): """ Get the unit of measure to interpret the `volume` field. By default, we consider that volumes are expressed in cubic meters. Users can configure to express them in cubic feet by adding an ir.config_parameter record with "product.volume_in_cubic_feet" as key and "1" as value. """ - get_param = self.env['ir.config_parameter'].sudo().get_param - return "ft³" if get_param('product.volume_in_cubic_feet') == '1' else "m³" + product_length_in_feet_param = self.env['ir.config_parameter'].sudo().get_param('product.volume_in_cubic_feet') + if product_length_in_feet_param == '1': + return self.env.ref('uom.product_uom_cubic_foot') + else: + return self.env.ref('uom.product_uom_cubic_meter') + + @api.model + def _get_weight_uom_name_from_ir_config_parameter(self): + return self._get_weight_uom_id_from_ir_config_parameter().display_name + + @api.model + def _get_length_uom_name_from_ir_config_parameter(self): + return self._get_length_uom_id_from_ir_config_parameter().display_name + + @api.model + def _get_volume_uom_name_from_ir_config_parameter(self): + return self._get_volume_uom_id_from_ir_config_parameter().display_name + + def _compute_weight_uom_name(self): + for template in self: + template.weight_uom_name = self._get_weight_uom_name_from_ir_config_parameter() def _compute_volume_uom_name(self): for template in self: diff --git a/addons/product/models/res_config_settings.py b/addons/product/models/res_config_settings.py index 5c740e8ea8c..96bbc88c5f9 100644 --- a/addons/product/models/res_config_settings.py +++ b/addons/product/models/res_config_settings.py @@ -26,8 +26,8 @@ class ResConfigSettings(models.TransientModel): ], default='basic', string="Pricelists Method", config_parameter='product.product_pricelist_setting', help="Multiple prices: Pricelists with fixed price rules by product,\nAdvanced rules: enables advanced price rules for pricelists.") product_weight_in_lbs = fields.Selection([ - ('0', 'Kilogram'), - ('1', 'Pound'), + ('0', 'Kilograms'), + ('1', 'Pounds'), ], 'Weight unit of measure', config_parameter='product.weight_in_lbs', default='0') product_volume_volume_in_cubic_feet = fields.Selection([ ('0', 'Cubic Meters'), diff --git a/addons/product/views/res_config_settings_views.xml b/addons/product/views/res_config_settings_views.xml index 4e430f7fcff..3325b056a4b 100644 --- a/addons/product/views/res_config_settings_views.xml +++ b/addons/product/views/res_config_settings_views.xml @@ -6,15 +6,15 @@ -

Products

+

Units of Measure

-