summaryrefslogtreecommitdiff
path: root/addons/mrp_account
diff options
context:
space:
mode:
authorDebauche Stéphane <std@odoo.com>2019-12-02 14:47:07 +0000
committerDebauche Stéphane <std@odoo.com>2019-12-06 10:58:03 +0000
commit42d3a82a809b15652ee3dd61ff3ec414fe7a76cb (patch)
tree0cfeb33d37ec2e0877852de917f90231b2e69f85 /addons/mrp_account
parentd6458e68df909898818ed3699c49f917ee3b561f (diff)
[IMP] stock_account: remove the wizard which change the ``standard_price``
Overwrite the method ``write`` of the model ``product.product``. When we write on ``standard_price``, if - the context key ``disable_auto_svl`` is not set - the ``cost_method`` is not "fifo" We automatically compute ``stock.valuation.layer`` (before we needed to manually call ``_change_standard_price``) Task #2031422 closes odoo/odoo#41265 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons/mrp_account')
-rw-r--r--addons/mrp_account/models/product.py20
-rw-r--r--addons/mrp_account/tests/test_bom_price.py6
-rw-r--r--addons/mrp_account/views/product_views.xml28
3 files changed, 24 insertions, 30 deletions
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 @@
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]"/>
<field name="arch" type="xml">
- <xpath expr="//span[@name='update_cost_price']" position="inside">
+ <xpath expr="//div[@name='standard_price_uom']" position="inside">
+ <field name="cost_method" invisible="1"/>
+ <field name="valuation" invisible="1"/>
<button name="button_bom_cost"
string="Compute Price from BoM" type="object"
attrs="{'invisible': ['|', ('bom_count', '=', 0), '&amp;', ('valuation', '=', 'real_time'), ('cost_method', '=', 'fifo')]}"
@@ -24,7 +26,9 @@
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]"/>
<field name="arch" type="xml">
- <xpath expr="//span[@name='update_cost_price']" position="inside">
+ <xpath expr="//div[@name='standard_price_uom']" position="inside">
+ <field name="cost_method" invisible="1"/>
+ <field name="valuation" invisible="1"/>
<button name="button_bom_cost"
string="Compute Price from BoM" type="object"
attrs="{'invisible': ['|', ('bom_count', '=', 0), '&amp;', ('valuation', '=', 'real_time'), ('cost_method', '=', 'fifo')]}"
@@ -41,14 +45,20 @@
<field name="inherit_id" ref="product.product_variant_easy_edit_view"/>
<field name="arch" type="xml">
<data>
- <xpath expr="//div[@name='update_cost_price']" position="inside">
+ <xpath expr="//field[@name='standard_price']" position="replace">
<field name="bom_count" invisible="1"/>
- <button name="button_bom_cost"
- string="Compute Price from BoM"
- type="object"
- attrs="{'invisible': ['|', ('bom_count', '=', 0), '&amp;', ('valuation', '=', 'real_time'), ('cost_method', '=', 'fifo')]}"
- help="Compute the price of the product using products and operations of related bill of materials, for manufactured products only."
- class="oe_link oe_read_only pt-0"/>
+ <field name="cost_method" invisible="1"/>
+ <field name="valuation" invisible="1"/>
+ <label for="standard_price"/>
+ <div>
+ <field name="standard_price" widget='monetary' options="{'currency_field': 'cost_currency_id'}"/>
+ <button name="button_bom_cost"
+ string="Compute Price from BoM"
+ type="object"
+ attrs="{'invisible': ['|', ('bom_count', '=', 0), '&amp;', ('valuation', '=', 'real_time'), ('cost_method', '=', 'fifo')]}"
+ help="Compute the price of the product using products and operations of related bill of materials, for manufactured products only."
+ class="oe_link oe_read_only pt-0"/>
+ </div>
</xpath>
</data>
</field>