diff --git a/stock_change_qty_reason/README.rst b/stock_change_qty_reason/README.rst new file mode 100644 index 000000000..74fb7a436 --- /dev/null +++ b/stock_change_qty_reason/README.rst @@ -0,0 +1,47 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Stock Change Quantity Reason +============================ + +This module extends the product stock management and allows to set a reason +in the wizard when changing the product quantity. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/167/8.0 + +Credits +======= + +Contributors +------------ + +* Denis Roussel + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/stock_change_qty_reason/__init__.py b/stock_change_qty_reason/__init__.py new file mode 100644 index 000000000..408a6001b --- /dev/null +++ b/stock_change_qty_reason/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +from . import models +from . import wizard diff --git a/stock_change_qty_reason/__openerp__.py b/stock_change_qty_reason/__openerp__.py new file mode 100644 index 000000000..b3447b4f4 --- /dev/null +++ b/stock_change_qty_reason/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': "Stock Change Quantity Reason", + 'summary': """ + Stock Quantity Change Reason """, + 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', + 'website': "http://acsone.eu", + 'category': 'Warehouse Management', + 'version': '8.0.1.0.0', + 'license': 'AGPL-3', + 'depends': [ + 'stock', + ], + 'data': [ + 'wizard/stock_product_change_qty.xml' + ], +} diff --git a/stock_change_qty_reason/models/__init__.py b/stock_change_qty_reason/models/__init__.py new file mode 100644 index 000000000..cdc73095f --- /dev/null +++ b/stock_change_qty_reason/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import stock diff --git a/stock_change_qty_reason/models/stock.py b/stock_change_qty_reason/models/stock.py new file mode 100644 index 000000000..5f6ffa7f7 --- /dev/null +++ b/stock_change_qty_reason/models/stock.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import models, api + + +class StockInventoryLine(models.Model): + _inherit = "stock.inventory.line" + + @api.model + def _resolve_inventory_line(self, inventory_line): + + move_id = super(StockInventoryLine, + self)._resolve_inventory_line(inventory_line) + + reason = self.env.context.get('change_quantity_reason', False) + if reason and move_id: + move = self.env['stock.move'].browse(move_id) + + if move.origin: + move.origin = ' ,'.join([move.origin, reason]) + else: + move.origin = reason + + return move_id diff --git a/stock_change_qty_reason/tests/__init__.py b/stock_change_qty_reason/tests/__init__.py new file mode 100644 index 000000000..aaa5518ba --- /dev/null +++ b/stock_change_qty_reason/tests/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import test_stock_change_qty_reason 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 new file mode 100644 index 000000000..4a5cf19ff --- /dev/null +++ b/stock_change_qty_reason/tests/test_stock_change_qty_reason.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# © 2016 Denis Roussel, Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import openerp.tests.common as common + + +class TestStockQuantityChangeReason(common.TransactionCase): + + def _product_change_qty(self, product, new_qty, reason): + wizard_model = self.env['stock.change.product.qty'] + wizard = wizard_model.create({'product_id': product.id, + 'new_quantity': new_qty, + 'reason': reason}) + wizard.change_product_qty() + + def test_product_change_qty(self): + """ Check product quantity update move reason is well set + """ + + # set product in each period + product2 = self.env.ref('product.product_product_37') + product3 = self.env.ref('product.product_product_38') + product4 = self.env.ref('product.product_product_39') + product5 = self.env.ref('product.product_product_40') + product6 = self.env.ref('product.product_product_41') + + self._product_change_qty(product2, 10, 'product_37_reason') + self._product_change_qty(product3, 0, 'product_38_reason') + self._product_change_qty(product4, 0, 'product_39_reason') + self._product_change_qty(product5, 10, 'product_40_reason') + self._product_change_qty(product6, 0, 'product_41_reason') + + move2 = self.env['stock.move'].search([('product_id', '=', + product2.id)], limit=1, + order='id desc') + move3 = self.env['stock.move'].search([('product_id', '=', + product3.id)], + limit=1, order='id desc') + move4 = self.env['stock.move'].search([('product_id', '=', + product4.id)], + limit=1, order='id desc') + move5 = self.env['stock.move'].search([('product_id', '=', + product5.id)], + limit=1, order='id desc') + move6 = self.env['stock.move'].search([('product_id', '=', + product6.id)], + limit=1, order='id desc') + + self.assertEqual(move2.origin, 'product_37_reason') + self.assertFalse(move3) + self.assertFalse(move4) + self.assertEqual(move5.origin, 'product_40_reason') + self.assertFalse(move6) diff --git a/stock_change_qty_reason/wizard/__init__.py b/stock_change_qty_reason/wizard/__init__.py new file mode 100644 index 000000000..2bce51f06 --- /dev/null +++ b/stock_change_qty_reason/wizard/__init__.py @@ -0,0 +1 @@ +from . import stock_change_product_qty diff --git a/stock_change_qty_reason/wizard/stock_change_product_qty.py b/stock_change_qty_reason/wizard/stock_change_product_qty.py new file mode 100644 index 000000000..d4807bda2 --- /dev/null +++ b/stock_change_qty_reason/wizard/stock_change_product_qty.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import models, fields, api + + +class StockChangeProductQty(models.TransientModel): + _inherit = 'stock.change.product.qty' + + reason = fields.Char('Reason', + help='Type in a reason for the ' + 'product quantity change') + + @api.multi + def change_product_qty(self): + if self.reason: + this = self.with_context(change_quantity_reason=self.reason) + + return super(StockChangeProductQty, this).change_product_qty() + + return super(StockChangeProductQty, self).change_product_qty() diff --git a/stock_change_qty_reason/wizard/stock_product_change_qty.xml b/stock_change_qty_reason/wizard/stock_product_change_qty.xml new file mode 100644 index 000000000..9aeffba0d --- /dev/null +++ b/stock_change_qty_reason/wizard/stock_product_change_qty.xml @@ -0,0 +1,15 @@ + + + + + Change Product Quantity Reason + stock.change.product.qty + + + + + + + + +