From 767584e85ae519cd779d1a1cc10df9cf92f46e6b Mon Sep 17 00:00:00 2001 From: hveficent Date: Wed, 2 Jan 2019 17:16:43 +0100 Subject: [PATCH] [11.0][IMP] Add optional encoded reason management --- stock_change_qty_reason/README.rst | 25 +++++- stock_change_qty_reason/__manifest__.py | 10 ++- stock_change_qty_reason/models/__init__.py | 3 + .../models/res_config_settings.py | 14 ++++ .../models/stock_inventory_line.py | 18 +++-- .../models/stock_inventory_line_reason.py | 17 ++++ stock_change_qty_reason/models/stock_move.py | 10 +++ stock_change_qty_reason/readme/CONFIGURE.rst | 15 ++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 5 +- .../security/ir.model.access.csv | 3 + .../security/stock_security.xml | 7 ++ .../static/description/index.html | 43 +++++++--- .../tests/test_stock_change_qty_reason.py | 65 ++++++++++++---- .../views/base_config_view.xml | 31 ++++++++ .../stock_inventory_line_reason_view.xml | 39 ++++++++++ .../views/stock_inventory_line_view.xml | 78 +++++++++++++++++++ .../wizard/stock_change_product_qty.py | 26 +++++-- .../wizard/stock_product_change_qty.xml | 38 ++++++--- 19 files changed, 394 insertions(+), 54 deletions(-) create mode 100644 stock_change_qty_reason/models/res_config_settings.py create mode 100644 stock_change_qty_reason/models/stock_inventory_line_reason.py create mode 100644 stock_change_qty_reason/models/stock_move.py create mode 100644 stock_change_qty_reason/readme/CONFIGURE.rst create mode 100644 stock_change_qty_reason/security/ir.model.access.csv create mode 100644 stock_change_qty_reason/security/stock_security.xml create mode 100644 stock_change_qty_reason/views/base_config_view.xml create mode 100644 stock_change_qty_reason/views/stock_inventory_line_reason_view.xml create mode 100644 stock_change_qty_reason/views/stock_inventory_line_view.xml diff --git a/stock_change_qty_reason/README.rst b/stock_change_qty_reason/README.rst index 0c4321864..b03cf7a04 100644 --- a/stock_change_qty_reason/README.rst +++ b/stock_change_qty_reason/README.rst @@ -26,13 +26,35 @@ Stock Change Quantity Reason |badge1| |badge2| |badge3| |badge4| |badge5| This module extends the product stock management and allows to set a reason -in the wizard when changing the product quantity. +in the wizard when changing the product quantity or in inventory adjustments +per line. + +It also can manage preset reasons optionally. **Table of contents** .. contents:: :local: +Configuration +============= + +To enable preset reason feature, you must: + +- Go to: Inventory > Settings > Inventory Adjustment +- Enable: Preset Change Qty Reason +- Enable: Technical Settings > Manage Stock Change Qty Preset Reasons + +Once is activate you will require te add a Preset reason to validate stock +products change quantity. + + +To allow an Stock Manager configure preset reasons easily, you should: + +- Select Stock Manager user on: Settings > Users +- Enable: Technical Settings > Manage Stock Change Qty Preset Reasons +- Go to Inventory > Configuration > Inventory Adjustment > Change Qty Reasons + Bug Tracker =========== @@ -57,6 +79,7 @@ Contributors * Denis Roussel * Meyomesse Gilles * Andreas Dian S.P +* Héctor Villarreal Maintainers ~~~~~~~~~~~ diff --git a/stock_change_qty_reason/__manifest__.py b/stock_change_qty_reason/__manifest__.py index 0d7b9370b..00ea56466 100644 --- a/stock_change_qty_reason/__manifest__.py +++ b/stock_change_qty_reason/__manifest__.py @@ -1,18 +1,24 @@ # 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). { 'name': "Stock Change Quantity Reason", 'summary': """ Stock Quantity Change Reason """, 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', - 'website': "http://acsone.eu", + 'website': "https://github.com/OCA/stock-logistics-warehouse", 'category': 'Warehouse Management', - 'version': '11.0.1.0.0', + 'version': '11.0.2.0.0', 'license': 'AGPL-3', 'depends': [ 'stock', ], 'data': [ + 'security/ir.model.access.csv', + 'security/stock_security.xml', + 'views/base_config_view.xml', + 'views/stock_inventory_line_reason_view.xml', + 'views/stock_inventory_line_view.xml', 'wizard/stock_product_change_qty.xml' ], 'installable': True, diff --git a/stock_change_qty_reason/models/__init__.py b/stock_change_qty_reason/models/__init__.py index da871d39e..4e1329aa1 100644 --- a/stock_change_qty_reason/models/__init__.py +++ b/stock_change_qty_reason/models/__init__.py @@ -1,3 +1,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import res_config_settings from . import stock_inventory_line +from . import stock_inventory_line_reason +from . import stock_move diff --git a/stock_change_qty_reason/models/res_config_settings.py b/stock_change_qty_reason/models/res_config_settings.py new file mode 100644 index 000000000..1a688b3d9 --- /dev/null +++ b/stock_change_qty_reason/models/res_config_settings.py @@ -0,0 +1,14 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + group_qty_reason_preset = fields.Boolean( + string="Preset Change Qty Reason", + required=True, + implied_group='stock_change_qty_reason.group_qty_reason_preset', + help="Enable use of predefined Reasons to manage Inventory Adjustments" + "and Product Update Quantities Wizard.") diff --git a/stock_change_qty_reason/models/stock_inventory_line.py b/stock_change_qty_reason/models/stock_inventory_line.py index 1e88c69f5..4cddd34b8 100644 --- a/stock_change_qty_reason/models/stock_inventory_line.py +++ b/stock_change_qty_reason/models/stock_inventory_line.py @@ -1,22 +1,28 @@ # Copyright 2016-2017 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import fields, models class StockInventoryLine(models.Model): """Class to inherit model stock.inventory.line""" _inherit = "stock.inventory.line" + reason = fields.Char(help='Type in a reason for the ' + 'product quantity change') + preset_reason_id = fields.Many2one('stock.inventory.line.reason') + def _get_move_values(self, qty, location_id, location_dest_id, out): """Function to super _get_move_value""" res = super(StockInventoryLine, self)._get_move_values( qty, location_id, location_dest_id, out) + context = self.env.context.get( + 'change_quantity_reason', False) or self.reason \ + if not self.preset_reason_id else self.preset_reason_id.name if res.get('origin'): - res['origin'] = ' ,'.join( - [res.get('origin'), - self.env.context.get('change_quantity_reason', False)]) + res['origin'] = ' ,'.join([res.get('origin'), context]) else: - res['origin'] = self.env.context.get('change_quantity_reason', - False) + res['origin'] = context + if self.preset_reason_id: + res['preset_reason_id'] = self.preset_reason_id.id return res diff --git a/stock_change_qty_reason/models/stock_inventory_line_reason.py b/stock_change_qty_reason/models/stock_inventory_line_reason.py new file mode 100644 index 000000000..b20bdf216 --- /dev/null +++ b/stock_change_qty_reason/models/stock_inventory_line_reason.py @@ -0,0 +1,17 @@ +# 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 fields, models + + +class StockInventoryLineReason(models.Model): + + _name = 'stock.inventory.line.reason' + + name = fields.Char('Reason Name') + description = fields.Text('Reason Description') + active = fields.Boolean(default=True) + + _sql_constraints = [ + ('name_unique', 'UNIQUE(name)', + 'You cannot have two reason with the same name.'), + ] diff --git a/stock_change_qty_reason/models/stock_move.py b/stock_change_qty_reason/models/stock_move.py new file mode 100644 index 000000000..1ef674efe --- /dev/null +++ b/stock_change_qty_reason/models/stock_move.py @@ -0,0 +1,10 @@ +# Copyright 2019 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + preset_reason_id = fields.Many2one('stock.inventory.line.reason', + required=False) diff --git a/stock_change_qty_reason/readme/CONFIGURE.rst b/stock_change_qty_reason/readme/CONFIGURE.rst new file mode 100644 index 000000000..14d153b4c --- /dev/null +++ b/stock_change_qty_reason/readme/CONFIGURE.rst @@ -0,0 +1,15 @@ +To enable preset reason feature, you must: + +- Go to: Inventory > Settings > Inventory Adjustment +- Enable: Preset Change Qty Reason +- Enable: Technical Settings > Manage Stock Change Qty Preset Reasons + +Once is activate you will require te add a Preset reason to validate stock +products change quantity. + + +To allow an Stock Manager configure preset reasons easily, you should: + +- Select Stock Manager user on: Settings > Users +- Enable: Technical Settings > Manage Stock Change Qty Preset Reasons +- Go to Inventory > Configuration > Inventory Adjustment > Change Qty Reasons diff --git a/stock_change_qty_reason/readme/CONTRIBUTORS.rst b/stock_change_qty_reason/readme/CONTRIBUTORS.rst index 264e42ade..0ab42b8a4 100644 --- a/stock_change_qty_reason/readme/CONTRIBUTORS.rst +++ b/stock_change_qty_reason/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Denis Roussel * Meyomesse Gilles * Andreas Dian S.P +* Héctor Villarreal diff --git a/stock_change_qty_reason/readme/DESCRIPTION.rst b/stock_change_qty_reason/readme/DESCRIPTION.rst index bcaa884ca..029c2af4b 100644 --- a/stock_change_qty_reason/readme/DESCRIPTION.rst +++ b/stock_change_qty_reason/readme/DESCRIPTION.rst @@ -1,2 +1,5 @@ This module extends the product stock management and allows to set a reason -in the wizard when changing the product quantity. +in the wizard when changing the product quantity or in inventory adjustments +per line. + +It also can manage preset reasons optionally. diff --git a/stock_change_qty_reason/security/ir.model.access.csv b/stock_change_qty_reason/security/ir.model.access.csv new file mode 100644 index 000000000..747b1302b --- /dev/null +++ b/stock_change_qty_reason/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_stock_inventory_line_reason_user,stock.inventory.line.reason,model_stock_inventory_line_reason,stock.group_stock_user,1,0,0,0 +access_stock_inventory_line_reason_manager,stock.inventory.line.reason,model_stock_inventory_line_reason,stock.group_stock_manager,1,1,1,1 diff --git a/stock_change_qty_reason/security/stock_security.xml b/stock_change_qty_reason/security/stock_security.xml new file mode 100644 index 000000000..80fac1de4 --- /dev/null +++ b/stock_change_qty_reason/security/stock_security.xml @@ -0,0 +1,7 @@ + + + + Manage Stock Change Qty Preset Reasons + + + diff --git a/stock_change_qty_reason/static/description/index.html b/stock_change_qty_reason/static/description/index.html index e8f958847..13cc2fc68 100644 --- a/stock_change_qty_reason/static/description/index.html +++ b/stock_change_qty_reason/static/description/index.html @@ -369,21 +369,41 @@ ul.auto-toc { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

This module extends the product stock management and allows to set a reason -in the wizard when changing the product quantity.

+in the wizard when changing the product quantity or in inventory adjustments +per line.

+

It also can manage preset reasons optionally.

Table of contents

+
+

Configuration

+

To enable preset reason feature, you must:

+
    +
  • Go to: Inventory > Settings > Inventory Adjustment
  • +
  • Enable: Preset Change Qty Reason
  • +
  • Enable: Technical Settings > Manage Stock Change Qty Preset Reasons
  • +
+

Once is activate you will require te add a Preset reason to validate stock +products change quantity.

+

To allow an Stock Manager configure preset reasons easily, you should:

+
    +
  • Select Stock Manager user on: Settings > Users
  • +
  • Enable: Technical Settings > Manage Stock Change Qty Preset Reasons
  • +
  • Go to Inventory > Configuration > Inventory Adjustment > Change Qty Reasons
  • +
+
-

Bug Tracker

+

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 @@ -391,23 +411,24 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • ACSONE SA/NV
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

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

+
+
+
+ +
+
+
+
+
+ + + + + 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 + + + + + + + + +