- Automate inter-company transactions
+
+
+
-
-
Save this page and come back here to set up the feature.
+
+
+
+ Automate inter-company transactions
+
+
+
Save this page and come back here to set up the feature.
+
diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py
index e7e5dfa5e23..8e4c252a4c0 100644
--- a/addons/delivery/models/stock_picking.py
+++ b/addons/delivery/models/stock_picking.py
@@ -51,12 +51,6 @@ class StockMoveLine(models.Model):
class StockPicking(models.Model):
_inherit = 'stock.picking'
- def _default_uom(self):
- weight_uom_id = self.env.ref('product.product_uom_kgm', raise_if_not_found=False)
- if not weight_uom_id:
- uom_categ_id = self.env.ref('product.product_uom_categ_kgm').id
- weight_uom_id = self.env['product.uom'].search([('category_id', '=', uom_categ_id), ('factor', '=', 1)], limit=1)
- return weight_uom_id
@api.one
@api.depends('move_line_ids')
@@ -89,7 +83,7 @@ class StockPicking(models.Model):
weight = fields.Float(compute='_cal_weight', digits=dp.get_precision('Stock Weight'), store=True)
carrier_tracking_ref = fields.Char(string='Tracking Reference', copy=False)
carrier_tracking_url = fields.Char(string='Tracking URL', compute='_compute_carrier_tracking_url')
- weight_uom_id = fields.Many2one('product.uom', string='Unit of Measure', required=True, readonly="1", help="Unit of measurement for Weight", default=_default_uom)
+ weight_uom_id = fields.Many2one('product.uom', string='Unit of Measure', compute='_compute_weight_uom_id', help="Unit of measurement for Weight")
package_ids = fields.Many2many('stock.quant.package', compute='_compute_packages', string='Packages')
weight_bulk = fields.Float('Bulk Weight', compute='_compute_bulk_weight')
shipping_weight = fields.Float("Weight for Shipping", compute='_compute_shipping_weight')
@@ -99,6 +93,11 @@ class StockPicking(models.Model):
for picking in self:
picking.carrier_tracking_url = picking.carrier_id.get_tracking_link(picking) if picking.carrier_id and picking.carrier_tracking_ref else False
+ def _compute_weight_uom_id(self):
+ weight_uom_id = self.env['product.template']._get_weight_uom_id_from_ir_config_parameter()
+ for picking in self:
+ picking.weight_uom_id = weight_uom_id
+
@api.depends('move_lines')
def _cal_weight(self):
for picking in self:
diff --git a/addons/product/models/product.py b/addons/product/models/product.py
index 797bbb7fe79..f9ab4b1780f 100644
--- a/addons/product/models/product.py
+++ b/addons/product/models/product.py
@@ -136,7 +136,7 @@ class ProductProduct(models.Model):
volume = fields.Float('Volume', help="The volume in m3.")
weight = fields.Float(
'Weight', digits=dp.get_precision('Stock Weight'),
- help="The weight of the contents in Kg, not including any packaging, etc.")
+ help="Weight of the product, packaging not included. The unit of measure can be changed in the general settings")
pricelist_item_ids = fields.Many2many(
'product.pricelist.item', 'Pricelist Items', compute='_get_pricelist_items')
diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py
index a0265d630b2..3f93f08d450 100644
--- a/addons/product/models/product_template.py
+++ b/addons/product/models/product_template.py
@@ -89,6 +89,8 @@ class ProductTemplate(models.Model):
'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('product.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)
sale_ok = fields.Boolean(
'Can be Sold', default=True,
@@ -234,6 +236,25 @@ class ProductTemplate(models.Model):
for template in (self - unique_variants):
template.weight = 0.0
+ @api.model
+ def _get_weight_uom_id_from_ir_config_parameter(self):
+ """ Get the unit of measure to interpret the `weight` field. By default, we considerer
+ that weights are expressed in kilograms. Users can configure to express them in pounds
+ 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')
+ if product_weight_in_lbs_param == '1':
+ return self.env.ref('product.product_uom_lb')
+ else:
+ return self.env.ref('product.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.one
def _set_weight(self):
if len(self.product_variant_ids) == 1:
diff --git a/addons/product/models/res_config_settings.py b/addons/product/models/res_config_settings.py
index 9fd8acfc626..ac6b4ac5b43 100644
--- a/addons/product/models/res_config_settings.py
+++ b/addons/product/models/res_config_settings.py
@@ -24,6 +24,10 @@ class ResConfigSettings(models.TransientModel):
implied_group='product.group_product_pricelist')
group_pricelist_item = fields.Boolean("Show pricelists to customers",
implied_group='product.group_pricelist_item')
+ product_weight_in_lbs = fields.Selection([
+ ('0', 'Kilogram'),
+ ('1', 'Pound'),
+ ], 'Weight unit of measure', config_parameter='product.weight_in_lbs', default='0')
@api.model
diff --git a/addons/product/views/product_views.xml b/addons/product/views/product_views.xml
index 7d95acc3c7b..95d1a4fbffd 100644
--- a/addons/product/views/product_views.xml
+++ b/addons/product/views/product_views.xml
@@ -55,6 +55,18 @@
+
+
+
+
+
+
+
+
+
+ m³
+
+
diff --git a/addons/product/views/res_config_settings_views.xml b/addons/product/views/res_config_settings_views.xml
index bb23206d34a..b67e2708774 100644
--- a/addons/product/views/res_config_settings_views.xml
+++ b/addons/product/views/res_config_settings_views.xml
@@ -9,6 +9,26 @@
+
+ Products
+
+
+
+
+
+
+
+ In which unit of measure do you manage your weights
+
+
+
+
+
+
diff --git a/addons/stock/views/product_views.xml b/addons/stock/views/product_views.xml
index 9c30bd765d0..4d7a0f33c72 100644
--- a/addons/stock/views/product_views.xml
+++ b/addons/stock/views/product_views.xml
@@ -97,18 +97,6 @@
-
-
-
-
- kg
-
-
-
-
- m³
-
-