-
+
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
diff --git a/stock_change_qty_reason/tests/test_stock_change_qty_reason.py b/stock_change_qty_reason/tests/test_stock_change_qty_reason.py
index b434c527c..5a3dcb511 100644
--- a/stock_change_qty_reason/tests/test_stock_change_qty_reason.py
+++ b/stock_change_qty_reason/tests/test_stock_change_qty_reason.py
@@ -1,5 +1,6 @@
# pylint: disable=import-error,protected-access,too-few-public-methods
# Copyright 2016-2017 ACSONE SA/NV ()
+# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import SavepointCase
@@ -12,9 +13,11 @@ class TestStockQuantityChangeReason(SavepointCase):
super(TestStockQuantityChangeReason, cls).setUpClass()
# MODELS
+ cls.stock_move = cls.env['stock.move']
cls.product_product_model = cls.env['product.product']
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']
# INSTANCES
cls.category = cls.product_category_model.create({
@@ -26,12 +29,23 @@ class TestStockQuantityChangeReason(SavepointCase):
'categ_id': self.category.id,
'type': 'product'})
- def _product_change_qty(self, product, new_qty, reason):
- wizard = self.wizard_model.create({'product_id': product.id,
- 'new_quantity': new_qty,
- 'reason': reason})
+ def _product_change_qty(self, product, new_qty, reason,
+ preset_reason_id=None):
+ values = {
+ 'product_id': product.id,
+ 'new_quantity': new_qty,
+ 'reason': reason,
+ }
+ if preset_reason_id:
+ values.update({'preset_reason_id': preset_reason_id.id})
+ wizard = self.wizard_model.create(values)
wizard.change_product_qty()
+ def _create_reason(self, name, description=None):
+ return self.preset_reason_id.create({
+ 'name': name,
+ 'description': description})
+
def test_product_change_qty(self):
""" Check product quantity update move reason is well set
"""
@@ -51,19 +65,42 @@ class TestStockQuantityChangeReason(SavepointCase):
self._product_change_qty(product6, 0, 'product_6_reason')
# check stock moves created
- move2 = self.env['stock.move'].search([('product_id', '=',
- product2.id)])
- move3 = self.env['stock.move'].search([('product_id', '=',
- product3.id)])
- move4 = self.env['stock.move'].search([('product_id', '=',
- product4.id)])
- move5 = self.env['stock.move'].search([('product_id', '=',
- product5.id)])
- move6 = self.env['stock.move'].search([('product_id', '=',
- product6.id)])
+ move2 = self.stock_move.search([('product_id', '=',
+ product2.id)])
+ move3 = self.stock_move.search([('product_id', '=',
+ product3.id)])
+ move4 = self.stock_move.search([('product_id', '=',
+ product4.id)])
+ move5 = self.stock_move.search([('product_id', '=',
+ product5.id)])
+ move6 = self.stock_move.search([('product_id', '=',
+ product6.id)])
self.assertEqual(move2.origin, 'product_2_reason')
self.assertFalse(move3)
self.assertFalse(move4)
self.assertEqual(move5.origin, 'product_5_reason')
self.assertFalse(move6)
+
+ def test_product_change_qty_with_preset_reason(self):
+ """ Check product quantity update move reason is well set
+ """
+ # create reason
+ reason = self._create_reason('Test', 'Description Test')
+ # create products
+ product2 = self._create_product('product_product_2')
+ product3 = self._create_product('product_product_3')
+
+ # update qty on hand and add reason
+ self._product_change_qty(product2, 10, reason.name, reason)
+ self._product_change_qty(product3, 0, reason.name, reason)
+
+ # check stock moves created
+ move2 = self.stock_move.search([('product_id', '=',
+ product2.id)])
+ move3 = self.stock_move.search([('product_id', '=',
+ product3.id)])
+ # asserts
+ self.assertEqual(move2.origin, reason.name)
+ self.assertEqual(move2.preset_reason_id, reason)
+ self.assertFalse(move3)
diff --git a/stock_change_qty_reason/views/base_config_view.xml b/stock_change_qty_reason/views/base_config_view.xml
new file mode 100644
index 000000000..5fd3aa9e3
--- /dev/null
+++ b/stock_change_qty_reason/views/base_config_view.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+ Select qty_reason_preset config parameter
+ res.config.settings
+
+
+
+ Inventory Adjustment
+
+
+
+
+
+
+
+
+ Manage predefined change quantity reasons
+
+
+
+
+
+
+
+
+
diff --git a/stock_change_qty_reason/views/stock_inventory_line_reason_view.xml b/stock_change_qty_reason/views/stock_inventory_line_reason_view.xml
new file mode 100644
index 000000000..fb3f166d9
--- /dev/null
+++ b/stock_change_qty_reason/views/stock_inventory_line_reason_view.xml
@@ -0,0 +1,39 @@
+
+
+
+
+ Preset Reason
+ stock.inventory.line.reason
+
+
+
+
+
+
+ Change Qty Reasons
+ stock.inventory.line.reason
+ ir.actions.act_window
+ form
+ list,form
+
+
+
+
+
diff --git a/stock_change_qty_reason/views/stock_inventory_line_view.xml b/stock_change_qty_reason/views/stock_inventory_line_view.xml
new file mode 100644
index 000000000..2fa80aa49
--- /dev/null
+++ b/stock_change_qty_reason/views/stock_inventory_line_view.xml
@@ -0,0 +1,78 @@
+
+
+
+ stock.inventory.line.tree
+ stock.inventory.line
+
+
+
+
+
+
+
+
+
+ stock.inventory.line.tree.reason.code
+ stock.inventory.line
+
+
+
+
+
+
+
+
+
+
+ stock.inventory.line.tree
+ stock.inventory.line
+
+
+
+
+
+
+
+
+
+ stock.inventory.line.tree.reason.code
+ stock.inventory.line
+
+
+
+
+
+
+
+
+
+
+ stock.inventory.form.inherit
+ stock.inventory
+
+
+
+
+
+
+
+
+
+
+
+
+ stock.inventory.form.inherit.reason.code
+ stock.inventory
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/stock_change_qty_reason/wizard/stock_change_product_qty.py b/stock_change_qty_reason/wizard/stock_change_product_qty.py
index bc1aa21d5..4581b2ed5 100644
--- a/stock_change_qty_reason/wizard/stock_change_product_qty.py
+++ b/stock_change_qty_reason/wizard/stock_change_product_qty.py
@@ -1,18 +1,16 @@
# Copyright 2016-2017 ACSONE SA/NV ()
+# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-"""stock_change_product_qty"""
-
-
-from odoo import models, fields, api
+from odoo import api, fields, models
class StockChangeProductQty(models.TransientModel):
"""Class to inherit model stock.change.product.qty"""
_inherit = 'stock.change.product.qty'
- reason = fields.Char('Reason',
- help='Type in a reason for the '
- 'product quantity change')
+ reason = fields.Char(help='Type in a reason for the '
+ 'product quantity change')
+ preset_reason_id = fields.Many2one('stock.inventory.line.reason')
@api.multi
def change_product_qty(self):
@@ -21,3 +19,17 @@ class StockChangeProductQty(models.TransientModel):
this = self.with_context(change_quantity_reason=self.reason)
return super(StockChangeProductQty, this).change_product_qty()
return super(StockChangeProductQty, self).change_product_qty()
+
+ def _action_start_line(self):
+ res = super(StockChangeProductQty, self)._action_start_line()
+ if self.preset_reason_id:
+ res.update({'preset_reason_id': self.preset_reason_id.id,
+ 'reason': self.preset_reason_id.name})
+ elif self.reason:
+ res.update({'reason': self.reason})
+ return res
+
+ @api.onchange('preset_reason_id')
+ def onchange_preset_reason_id(self):
+ if self.preset_reason_id:
+ self.reason = self.preset_reason_id.name
diff --git a/stock_change_qty_reason/wizard/stock_product_change_qty.xml b/stock_change_qty_reason/wizard/stock_product_change_qty.xml
index b5160715d..4d76e85ab 100644
--- a/stock_change_qty_reason/wizard/stock_product_change_qty.xml
+++ b/stock_change_qty_reason/wizard/stock_product_change_qty.xml
@@ -1,17 +1,31 @@
-
-
-
- Change Product Quantity Reason
- stock.change.product.qty
-
-
-
-
-
+
+
+ Change Product Quantity Reason
+ stock.change.product.qty
+
+
+
+
-
-
+
+
+
+
+ Change Product Quantity Reason
+ stock.change.product.qty
+
+
+
+
+
+
+
+
+