diff --git a/addons/mrp_account/models/product.py b/addons/mrp_account/models/product.py index da15e757cb3..61f067b020a 100644 --- a/addons/mrp_account/models/product.py +++ b/addons/mrp_account/models/product.py @@ -27,28 +27,18 @@ class ProductProduct(models.Model): def button_bom_cost(self): self.ensure_one() - price = self._get_price_from_bom() - if self.valuation == 'real_time': - action_rec = self.env.ref('stock_account.action_view_change_standard_price') - action = action_rec.read([])[0] - action['context'] = {'default_new_price': price} - return action - else: - self.standard_price = price + self._set_price_from_bom() def action_bom_cost(self): - real_time_products = self.filtered(lambda p: p.valuation == 'real_time') - if real_time_products: - raise UserError(_('The inventory valuation of some products %s is automated. You can only update their cost from the product form.') % (real_time_products.mapped('display_name'))) - boms_to_recompute = self.env['mrp.bom'].search(['|', ('product_id', 'in', self.ids), '&', ('product_id', '=', False), ('product_tmpl_id', 'in', self.mapped('product_tmpl_id').ids)]) for product in self: - product.standard_price = product._get_price_from_bom(boms_to_recompute) + product._set_price_from_bom(boms_to_recompute) - def _get_price_from_bom(self, boms_to_recompute=False): + def _set_price_from_bom(self, boms_to_recompute=False): self.ensure_one() bom = self.env['mrp.bom']._bom_find(product=self) - return self._compute_bom_price(bom, boms_to_recompute=boms_to_recompute) + if bom: + self.standard_price = self._compute_bom_price(bom, boms_to_recompute=boms_to_recompute) def _compute_bom_price(self, bom, boms_to_recompute=False): self.ensure_one() diff --git a/addons/mrp_account/tests/test_bom_price.py b/addons/mrp_account/tests/test_bom_price.py index 1273e3ecdba..b015080a883 100644 --- a/addons/mrp_account/tests/test_bom_price.py +++ b/addons/mrp_account/tests/test_bom_price.py @@ -182,9 +182,3 @@ class TestBom(common.TransactionCase): self.Product.browse([self.dining_table.id, self.table_head.id]).action_bom_cost() # Total cost of Dining Table = (718.75) + Total cost of all operations (125 + 10.42) = 854.17 self.assertEqual(float_compare(self.dining_table.standard_price, 854.17, precision_digits=2), 0, "After computing price from BoM price should be 786.46") - - def test_01_compute_price_inventory_valuation(self): - """Test update cost from bom in list view when inventory valuation is real time.""" - self.glass.categ_id.property_valuation = 'real_time' - with self.assertRaises(UserError): - self.dining_table.with_context(button=False).action_bom_cost() diff --git a/addons/mrp_account/views/product_views.xml b/addons/mrp_account/views/product_views.xml index 5ad16258b6b..2263a5f0cf0 100644 --- a/addons/mrp_account/views/product_views.xml +++ b/addons/mrp_account/views/product_views.xml @@ -7,7 +7,9 @@ - + + +