[12.0][IMP] Explode reason from Inventory Adjustment to lines

This commit is contained in:
hveficent
2019-05-28 10:52:14 +02:00
committed by Adrià Gil Sorribes
parent 333fe31804
commit 44b70b24bf
5 changed files with 85 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
'views/base_config_view.xml',
'views/stock_inventory_line_reason_view.xml',
'views/stock_inventory_line_view.xml',
'views/stock_inventory_view.xml',
'wizard/stock_product_change_qty.xml'
],
'installable': True,

View File

@@ -1,6 +1,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import res_config_settings
from . import stock_inventory
from . import stock_inventory_line
from . import stock_inventory_line_reason
from . import stock_move

View File

@@ -0,0 +1,30 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class StockInventory(models.Model):
_inherit = 'stock.inventory'
reason = fields.Char(help='Type in a reason for the '
'product quantity change')
preset_reason_id = fields.Many2one('stock.inventory.line.reason')
def _get_inventory_lines_values(self):
vals = super(StockInventory, self)._get_inventory_lines_values()
for val in vals:
if self.preset_reason_id:
val['preset_reason_id'] = self.preset_reason_id.id
elif self.reason:
val['reason'] = self.reason
return vals
@api.onchange('reason')
def onchange_reason(self):
for line in self.line_ids:
line.reason = self.reason
@api.onchange('preset_reason_id')
def onchange_preset_reason(self):
for line in self.line_ids:
line.preset_reason_id = self.preset_reason_id

View File

@@ -18,6 +18,7 @@ class TestStockQuantityChangeReason(SavepointCase):
cls.product_category_model = cls.env['product.category']
cls.wizard_model = cls.env['stock.change.product.qty']
cls.preset_reason_id = cls.env['stock.inventory.line.reason']
cls.stock_location = cls.env.ref('stock.stock_location_stock')
# INSTANCES
cls.category = cls.product_category_model.create({
@@ -104,3 +105,28 @@ class TestStockQuantityChangeReason(SavepointCase):
self.assertEqual(move2.origin, reason.name)
self.assertEqual(move2.preset_reason_id, reason)
self.assertFalse(move3)
def test_inventory_adjustment_onchange_reason_preset_reason(self):
""" Check that adding a reason or a preset reason explode to lines
"""
product2 = self._create_product('product_product_2')
self._product_change_qty(product2, 50, 'product_2_reason')
inventory = self.env['stock.inventory'].create({
'name': 'remove product2',
'filter': 'product',
'location_id': self.stock_location.id,
'product_id': product2.id,
})
inventory.preset_reason_id = self._create_reason('Test 1',
'Description Test 1')
inventory.action_start()
self.assertEqual(len(inventory.line_ids), 1)
inventory.preset_reason_id = self._create_reason('Test 2',
'Description Test 2')
inventory.onchange_preset_reason()
self.assertEquals(inventory.line_ids.preset_reason_id,
inventory.preset_reason_id)
inventory.reason = 'Reason 2'
inventory.onchange_reason()
self.assertEquals(inventory.line_ids.reason,
inventory.reason)

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="reason_stock_inventory_form_inherit" model="ir.ui.view">
<field name="name">stock.inventory.reason.form.inherit</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock.view_inventory_form"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="reason"/>
</field>
</field>
</record>
<record id="preset_reason_stock_inventory_form_inherit" model="ir.ui.view">
<field name="name">stock.inventory.reason.form.inherit.code</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="reason_stock_inventory_form_inherit"/>
<field name="groups_id" eval="[(4, ref('stock_change_qty_reason.group_qty_reason_preset'))]"/>
<field name="arch" type="xml">
<field name="reason" position="replace">
<field name="preset_reason_id"/>
</field>
</field>
</record>
</odoo>