[REF] mrp_account: adapt to valuation layers

A finished move is considered as an incoming move and will pass by
_create_in_svl. We thus compute the price_unit that will be set on the
valuation layer.

We also set a stat button on the MO displaying the valuation
layers, similar to the one on the picking.

task-1875873
This commit is contained in:
Simon Lejeune
2019-06-10 20:42:59 +00:00
parent 5c62700698
commit e93ede220d
4 changed files with 28 additions and 4 deletions
+4 -1
View File
@@ -21,7 +21,10 @@ If the automated inventory valuation is active, the necessary accounting entries
'depends': ['mrp', 'stock_account'],
"init_xml" : [],
"demo_xml" : [],
"data": ["views/product_views.xml"],
"data": [
"views/product_views.xml",
"views/mrp_production_views.xml",
],
'installable': True,
'auto_install': True,
}
+8 -2
View File
@@ -32,8 +32,7 @@ class MrpProduction(models.Model):
if finished_move.product_id.cost_method in ('fifo', 'average'):
qty_done = finished_move.product_uom._compute_quantity(finished_move.quantity_done, finished_move.product_id.uom_id)
extra_cost = self.extra_cost * qty_done
finished_move.price_unit = (sum([-m.value for m in consumed_moves]) + work_center_cost + extra_cost) / qty_done
finished_move.value = sum([-m.value for m in consumed_moves]) + work_center_cost + extra_cost
finished_move.price_unit = (sum([-m.stock_valuation_layer_ids.value for m in consumed_moves]) + work_center_cost + extra_cost) / qty_done
return True
def _prepare_wc_analytic_line(self, wc_line):
@@ -69,3 +68,10 @@ class MrpProduction(models.Model):
res = super(MrpProduction, self).button_mark_done()
self._costs_generate()
return res
def action_view_stock_valuation_layers(self):
self.ensure_one()
domain = [('id', 'in', (self.move_raw_ids + self.move_finished_ids).stock_valuation_layer_ids.ids)]
action = self.env.ref('stock_account.stock_valuation_layer_action').read()[0]
return dict(action, domain=domain)
+1 -1
View File
@@ -83,7 +83,7 @@ class TestMrpAccount(common.TransactionCase):
produce_wizard = produce_form.save()
produce_wizard.do_produce()
production_table.post_inventory()
move_value = production_table.move_finished_ids.filtered(lambda x: x.state == "done").value
move_value = production_table.move_finished_ids.filtered(lambda x: x.state == "done").stock_valuation_layer_ids.value
# 1 table head at 20 + 4 table leg at 15 + 4 bolt at 10 + 10 screw at 10 + 1*20 (extra cost)
self.assertEqual(move_value, 141, 'Thing should have the correct price')
@@ -0,0 +1,15 @@
<odoo>
<record id="mrp_production_form_view_inherited" model="ir.ui.view">
<field name="name">mrp.production.view.inherited</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button string="Valuation" type="object"
name="action_view_stock_valuation_layers"
class="oe_stat_button" icon="fa-dollar" groups="stock.group_stock_manager"
attrs="{'invisible': [('state', 'not in', ['done'])]}" />
</xpath>
</field>
</record>
</odoo>