[IMP] product,delivery: improve unit of measure display
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -13,13 +13,33 @@
|
||||
<field name="name"/>
|
||||
</h1>
|
||||
<group name="delivery">
|
||||
<group>
|
||||
<field name="package_carrier_type"/>
|
||||
<field name="height"/>
|
||||
<field name="width"/>
|
||||
<field name="packaging_length"/>
|
||||
<field name="max_weight"/>
|
||||
<label for="height"/>
|
||||
<div class="o_row" name="height">
|
||||
<field name="height"/>
|
||||
<span><field name="length_uom_name"/></span>
|
||||
</div>
|
||||
<label for="width"/>
|
||||
<div class="o_row" name="width">
|
||||
<field name="width"/>
|
||||
<span><field name="length_uom_name"/></span>
|
||||
</div>
|
||||
<label for="packaging_length"/>
|
||||
<div class="o_row" name="packaging_length">
|
||||
<field name="packaging_length"/>
|
||||
<span><field name="length_uom_name"/></span>
|
||||
</div>
|
||||
</group>
|
||||
<group>
|
||||
<label for="max_weight"/>
|
||||
<div class="o_row" name="max_weight">
|
||||
<field name="max_weight"/>
|
||||
<span><field name="weight_uom_name"/></span>
|
||||
</div>
|
||||
<field name="barcode"/>
|
||||
<field name="shipper_package_code"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@id='multi_company']" position="before">
|
||||
<h2>Products</h2>
|
||||
<h2>Units of Measure</h2>
|
||||
<div class="row mt16 o_settings_container" id="product_general_settings">
|
||||
<div class="col-12 col-lg-6 o_setting_box" id="weight_uom_setting">
|
||||
<div class="o_setting_left_pane">
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="product_weight_in_lbs" string="Weight Measurement"/>
|
||||
<label for="product_weight_in_lbs" string="Weight UoM"/>
|
||||
<div class="text-muted">
|
||||
Choose the unit to measure weight
|
||||
Define your weight unit of measure
|
||||
</div>
|
||||
<div class="content-group">
|
||||
<div class="mt16">
|
||||
@@ -25,9 +25,9 @@
|
||||
</div>
|
||||
<div class="col-12 col-lg-6 o_setting_box" id="manage_volume_uom_setting">
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="product_volume_volume_in_cubic_feet"/>
|
||||
<label for="product_volume_volume_in_cubic_feet" string="Volume UoM "/>
|
||||
<div class="text-muted">
|
||||
In which unit of measure do you manage your volumes
|
||||
Define your volume unit of measure
|
||||
</div>
|
||||
<div class="content-group">
|
||||
<div class="mt16">
|
||||
|
||||
Reference in New Issue
Block a user