From 03c84f2c76b44e8a6713ab17a191375b5a4898fc Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 10 Mar 2016 10:23:07 +0100 Subject: [PATCH] [FIX] sale, sale_stock: Changing the product uom When changing the product in a SO line, the uom must be change if the uom category of the product is different of the uom set. Closes #11241 opw:671367 --- addons/sale/sale.py | 2 +- addons/sale_stock/sale_stock.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 2925d35c545..6258d63e8b8 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -728,7 +728,7 @@ class SaleOrderLine(models.Model): vals = {} domain = {'product_uom': [('category_id', '=', self.product_id.uom_id.category_id.id)]} - if not (self.product_uom and (self.product_id.uom_id.category_id.id == self.product_uom.category_id.id)): + if not self.product_uom or (self.product_id.uom_id.category_id.id != self.product_uom.category_id.id): vals['product_uom'] = self.product_id.uom_id product = self.product_id.with_context( diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 9c7fe4bea02..9f04e4b5833 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -130,7 +130,13 @@ class SaleOrderLine(models.Model): return self._check_package() return {} - @api.onchange('product_id', 'product_uom_qty', 'product_uom', 'route_id') + @api.onchange('product_id') + def _onchange_product_id_uom_check_availability(self): + if not self.product_uom or (self.product_id.uom_id.category_id.id != self.product_uom.category_id.id): + self.product_uom = self.product_id.uom_id + self._onchange_product_id_check_availability() + + @api.onchange('product_uom_qty', 'product_uom', 'route_id') def _onchange_product_id_check_availability(self): if not self.product_id or not self.product_uom_qty or not self.product_uom: self.product_packaging = False