[IMP] product: Choose volume measure on products
Until now, the volume measure displayed on the product form was only in m³. We now allow to choose between m³ and ft³. So, we add volume selection field (m³/ft³) on general settings and it will be display on product and product variants form view as configuration. We also Remove tooltip from weight and volume field. And display weight (kg or lb(s)) in product and product variants form view correctly, because currently weight didn't display on product form view before save the product but after this commit weight will be display. This commit is related to task ID 1869002. closes odoo/odoo#26542
This commit is contained in:
committed by
Pierre Masereel
parent
96b103a8b1
commit
aa4b686bac
@@ -135,10 +135,8 @@ class ProductProduct(models.Model):
|
||||
help = "Cost used for stock valuation in standard price and as a first price to set in average/fifo. "
|
||||
"Also used as a base price for pricelists. "
|
||||
"Expressed in the default unit of measure of the product.")
|
||||
volume = fields.Float('Volume', help="The volume in m3.")
|
||||
weight = fields.Float(
|
||||
'Weight', digits=dp.get_precision('Stock Weight'),
|
||||
help="Weight of the product, packaging not included. The unit of measure can be changed in the general settings")
|
||||
volume = fields.Float('Volume')
|
||||
weight = fields.Float('Weight', digits=dp.get_precision('Stock Weight'))
|
||||
|
||||
pricelist_item_ids = fields.Many2many(
|
||||
'product.pricelist.item', 'Pricelist Items', compute='_get_pricelist_items')
|
||||
|
||||
@@ -35,6 +35,12 @@ class ProductTemplate(models.Model):
|
||||
def _get_default_uom_id(self):
|
||||
return self.env["uom.uom"].search([], limit=1, order='id').id
|
||||
|
||||
def _get_default_weight_uom(self):
|
||||
return self._get_weight_uom_name_from_ir_config_parameter()
|
||||
|
||||
def _get_default_volume_uom(self):
|
||||
return self._get_volume_uom_name_from_ir_config_parameter()
|
||||
|
||||
name = fields.Char('Name', index=True, required=True, translate=True)
|
||||
sequence = fields.Integer('Sequence', default=1, help='Gives the sequence order when displaying a product list')
|
||||
description = fields.Text(
|
||||
@@ -78,14 +84,12 @@ class ProductTemplate(models.Model):
|
||||
help = "Cost used for stock valuation in standard price and as a first price to set in average/FIFO.")
|
||||
|
||||
volume = fields.Float(
|
||||
'Volume', compute='_compute_volume', inverse='_set_volume',
|
||||
help="The volume in m3.", store=True)
|
||||
'Volume', compute='_compute_volume', inverse='_set_volume', store=True)
|
||||
volume_uom_name = fields.Char(string='Volume unit of measure label', compute='_compute_volume_uom_name', default=_get_default_volume_uom)
|
||||
weight = fields.Float(
|
||||
'Weight', compute='_compute_weight', digits=dp.get_precision('Stock Weight'),
|
||||
inverse='_set_weight', store=True,
|
||||
help="The weight of the contents in Kg, not including any packaging, etc.")
|
||||
weight_uom_id = fields.Many2one('uom.uom', string='Weight Unit of Measure', compute='_compute_weight_uom_id')
|
||||
weight_uom_name = fields.Char(string='Weight unit of measure label', related='weight_uom_id.name', readonly=True)
|
||||
inverse='_set_weight', store=True)
|
||||
weight_uom_name = fields.Char(string='Weight unit of measure label', compute='_compute_weight_uom_name', readonly=True, default=_get_default_weight_uom)
|
||||
|
||||
sale_ok = fields.Boolean('Can be Sold', default=True)
|
||||
purchase_ok = fields.Boolean('Can be Purchased', default=True)
|
||||
@@ -257,10 +261,27 @@ class ProductTemplate(models.Model):
|
||||
else:
|
||||
return self.env.ref('uom.product_uom_kgm')
|
||||
|
||||
def _compute_weight_uom_id(self):
|
||||
weight_uom_id = self._get_weight_uom_id_from_ir_config_parameter()
|
||||
for product_template in self:
|
||||
product_template.weight_uom_id = weight_uom_id
|
||||
@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()
|
||||
|
||||
@api.model
|
||||
def _get_volume_uom_name_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³"
|
||||
|
||||
def _compute_volume_uom_name(self):
|
||||
for template in self:
|
||||
template.volume_uom_name = self._get_volume_uom_name_from_ir_config_parameter()
|
||||
|
||||
@api.one
|
||||
def _set_weight(self):
|
||||
|
||||
@@ -28,6 +28,10 @@ class ResConfigSettings(models.TransientModel):
|
||||
('0', 'Kilogram'),
|
||||
('1', 'Pound'),
|
||||
], 'Weight unit of measure', config_parameter='product.weight_in_lbs', default='0')
|
||||
product_volume_volume_in_cubic_feet = fields.Selection([
|
||||
('0', 'Cubic Meters'),
|
||||
('1', 'Cubic Feet'),
|
||||
], 'Volume unit of measure', config_parameter='product.volume_in_cubic_feet', default='0')
|
||||
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
<label for="volume"/>
|
||||
<div class="o_row" name="volume">
|
||||
<field name="volume" string="Volume"/>
|
||||
<span>m³</span>
|
||||
<span><field name="volume_uom_name"/></span>
|
||||
</div>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
@@ -27,6 +27,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-lg-6 o_setting_box">
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="product_volume_volume_in_cubic_feet"/>
|
||||
<div class="text-muted">
|
||||
In which unit of measure do you manage your volumes
|
||||
</div>
|
||||
<div class="content-group">
|
||||
<div class="mt16">
|
||||
<field name="product_volume_volume_in_cubic_feet" class="o_light_label" widget="radio"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user