From 9f00afafac6987e4d1f5bb5e6ed8f27fffe073f9 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Tue, 18 Sep 2018 13:19:26 +0200 Subject: [PATCH] [11.0][MIG] procurement_auto_create_group --- procurement_auto_create_group/README.rst | 82 ++++++++----- procurement_auto_create_group/__init__.py | 3 - procurement_auto_create_group/__manifest__.py | 10 +- .../models/__init__.py | 6 +- .../{procurement.py => procurement_group.py} | 23 ++-- .../readme/CONFIGURE.rst | 8 ++ .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 9 ++ .../readme/USAGE.rst | 4 + .../tests/__init__.py | 3 - .../tests/test_auto_create.py | 111 ++++++++++++------ .../views/procurement_view.xml | 5 +- 12 files changed, 169 insertions(+), 97 deletions(-) rename procurement_auto_create_group/models/{procurement.py => procurement_group.py} (65%) create mode 100644 procurement_auto_create_group/readme/CONFIGURE.rst create mode 100644 procurement_auto_create_group/readme/CONTRIBUTORS.rst create mode 100644 procurement_auto_create_group/readme/DESCRIPTION.rst create mode 100644 procurement_auto_create_group/readme/USAGE.rst diff --git a/procurement_auto_create_group/README.rst b/procurement_auto_create_group/README.rst index e5b3eead4..9688340aa 100644 --- a/procurement_auto_create_group/README.rst +++ b/procurement_auto_create_group/README.rst @@ -1,13 +1,29 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - ============================= Procurement Auto Create Group ============================= +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/11.0/procurement_auto_create_group + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| + This module allows the system to propose automatically new procurement groups -in procurement orders. +when procuring. This capability is important when you want to make sure that all the stock moves resulting from this procurement will never be mixed with moves from @@ -16,57 +32,67 @@ other groups in stock transfers. The stock transfers resulting from the execution of these procurements will only contain stock moves created from that procurement. +**Table of contents** + +.. contents:: + :local: Configuration ============= -#. Go to *Inventory / Configuration / Settings* and check the option 'Advanced - routing of products using rules' and press the 'Apply' button. +#. Go to *Inventory / Configuration / Settings* and check the option + 'Multi-Step Routes' and press the 'Save' button. #. Activate the developer mode. -#. Go to *Inventory / Configuration / Routes / Routes* and check the option - 'Auto-create Procurement Group' to the pull rules where you want the - procurement groups to be automatically proposed. +#. Go to *Inventory / Configuration / Warehouse Management / Routes* + and select the route you want to change. Select the pull rule you wish + to change and Select 'Propagation of Procurement Group': 'Propagage'. + The checkbox 'Auto-create Procurement Group' will then appear and you can + set it if you want to procurement group to be automatically created. Usage ===== -#. Go to *Inventory / Reports / Procurement Exceptions*. -#. Create a new procurement order and make sure that it determines a pull rule +#. Create a new procurement and make sure that it determines a pull rule with the option 'Auto-create Procurement Group' set. -#. When you save the procurement order, a procurement group with format - 'PG/000001' will be created. - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/153/10.0 +#. When the procurement rule is executed, a procurement group with + format 'PG/000001' will be created. 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. +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. + +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +~~~~~~~ + +* Eficent + Contributors ------------- +~~~~~~~~~~~~ + * Jordi Ballester * Lois Rilo -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. 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. +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/procurement_auto_create_group/__init__.py b/procurement_auto_create_group/__init__.py index 47f24cdb7..0650744f6 100644 --- a/procurement_auto_create_group/__init__.py +++ b/procurement_auto_create_group/__init__.py @@ -1,4 +1 @@ -# # -*- coding: utf-8 -*- -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - from . import models diff --git a/procurement_auto_create_group/__manifest__.py b/procurement_auto_create_group/__manifest__.py index aebd594b4..15e878f3d 100644 --- a/procurement_auto_create_group/__manifest__.py +++ b/procurement_auto_create_group/__manifest__.py @@ -1,19 +1,19 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Procurement Auto Create Group", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", + "development_status": "Production/Stable", "license": "AGPL-3", "summary": "Allows to configure the system to propose automatically new " "procurement groups in procurement orders.", - "depends": [ - "procurement", - ], "author": "Eficent," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse Management", + "depends": [ + "stock", + ], "data": [ 'views/procurement_view.xml', ], diff --git a/procurement_auto_create_group/models/__init__.py b/procurement_auto_create_group/models/__init__.py index 01a85acda..d470e2b5f 100644 --- a/procurement_auto_create_group/models/__init__.py +++ b/procurement_auto_create_group/models/__init__.py @@ -1,6 +1,2 @@ -# -*- coding: utf-8 -*- -# Copyright 2017 Eficent Business and IT Consulting Services, S.L. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - from . import procurement_rule -from . import procurement +from . import procurement_group diff --git a/procurement_auto_create_group/models/procurement.py b/procurement_auto_create_group/models/procurement_group.py similarity index 65% rename from procurement_auto_create_group/models/procurement.py rename to procurement_auto_create_group/models/procurement_group.py index 6aa4a51a4..2c320ab01 100644 --- a/procurement_auto_create_group/models/procurement.py +++ b/procurement_auto_create_group/models/procurement_group.py @@ -6,8 +6,17 @@ from odoo import api, models, _ from odoo.exceptions import UserError -class ProcurementOrder(models.Model): - _inherit = 'procurement.order' +class ProcurementGroup(models.Model): + _inherit = 'procurement.group' + + @api.model + def _get_rule(self, product_id, location_id, values): + result = super()._get_rule(product_id, location_id, values) + if result and not values.get('group_id') and result.auto_create_group: + group_data = self._prepare_auto_procurement_group_data() + group = self.env['procurement.group'].create(group_data) + values['group_id'] = group + return result @api.model def _prepare_auto_procurement_group_data(self): @@ -18,13 +27,3 @@ class ProcurementOrder(models.Model): return { 'name': name } - - @api.multi - def _assign(self): - res = super(ProcurementOrder, self)._assign() - if (self.rule_id and not self.group_id and - self.rule_id.auto_create_group): - group_data = self._prepare_auto_procurement_group_data() - group = self.env['procurement.group'].create(group_data) - self.group_id = group - return res diff --git a/procurement_auto_create_group/readme/CONFIGURE.rst b/procurement_auto_create_group/readme/CONFIGURE.rst new file mode 100644 index 000000000..1d1bad1e4 --- /dev/null +++ b/procurement_auto_create_group/readme/CONFIGURE.rst @@ -0,0 +1,8 @@ +#. Go to *Inventory / Configuration / Settings* and check the option + 'Multi-Step Routes' and press the 'Save' button. +#. Activate the developer mode. +#. Go to *Inventory / Configuration / Warehouse Management / Routes* + and select the route you want to change. Select the pull rule you wish + to change and Select 'Propagation of Procurement Group': 'Propagage'. + The checkbox 'Auto-create Procurement Group' will then appear and you can + set it if you want to procurement group to be automatically created. diff --git a/procurement_auto_create_group/readme/CONTRIBUTORS.rst b/procurement_auto_create_group/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..6df2be2f8 --- /dev/null +++ b/procurement_auto_create_group/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Jordi Ballester +* Lois Rilo diff --git a/procurement_auto_create_group/readme/DESCRIPTION.rst b/procurement_auto_create_group/readme/DESCRIPTION.rst new file mode 100644 index 000000000..897e9271c --- /dev/null +++ b/procurement_auto_create_group/readme/DESCRIPTION.rst @@ -0,0 +1,9 @@ +This module allows the system to propose automatically new procurement groups +when procuring. + +This capability is important when you want to make sure that all the stock +moves resulting from this procurement will never be mixed with moves from +other groups in stock transfers. + +The stock transfers resulting from the execution of these procurements will +only contain stock moves created from that procurement. diff --git a/procurement_auto_create_group/readme/USAGE.rst b/procurement_auto_create_group/readme/USAGE.rst new file mode 100644 index 000000000..37c8da1e5 --- /dev/null +++ b/procurement_auto_create_group/readme/USAGE.rst @@ -0,0 +1,4 @@ +#. Create a new procurement and make sure that it determines a pull rule + with the option 'Auto-create Procurement Group' set. +#. When the procurement rule is executed, a procurement group with + format 'PG/000001' will be created. diff --git a/procurement_auto_create_group/tests/__init__.py b/procurement_auto_create_group/tests/__init__.py index e66ed1ed1..eb02eb3bb 100644 --- a/procurement_auto_create_group/tests/__init__.py +++ b/procurement_auto_create_group/tests/__init__.py @@ -1,4 +1 @@ -# -*- coding: utf-8 -*- -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - from . import test_auto_create diff --git a/procurement_auto_create_group/tests/test_auto_create.py b/procurement_auto_create_group/tests/test_auto_create.py index d7a2ce6e2..33e390266 100644 --- a/procurement_auto_create_group/tests/test_auto_create.py +++ b/procurement_auto_create_group/tests/test_auto_create.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -8,53 +7,89 @@ from odoo.tests.common import TransactionCase class TestProcurementAutoCreateGroup(TransactionCase): def setUp(self, *args, **kwargs): super(TestProcurementAutoCreateGroup, self).setUp(*args, **kwargs) - self.po_model = self.env['procurement.order'] - self.pr_model = self.env['procurement.rule'] - self.product_12 = self.env.ref('product.product_product_12') - # Needed to avoid the dependency with stock: - if self.env.registry.models.get('stock.picking'): - picking_type_id = self.env.ref('stock.picking_type_internal').id - else: - picking_type_id = False + self.group_obj = self.env['procurement.group'] + self.rule_obj = self.env['procurement.rule'] + self.route_obj = self.env['stock.location.route'] + self.move_obj = self.env['stock.move'] + self.product_obj = self.env['product.product'] - # Create rules: - self.no_auto_create = self.pr_model.create({ - 'name': 'rule without autocreate', - 'auto_create_group': False, - 'action': [], - 'picking_type_id': picking_type_id, + self.warehouse = self.env.ref('stock.warehouse0') + self.location = self.env.ref('stock.stock_location_stock') + loc_components = self.env.ref('stock.stock_location_components') + picking_type_id = self.env.ref('stock.picking_type_internal').id + + # Create rules and routes: + route_auto = self.route_obj.create({ + 'name': 'Auto Create Group', }) - self.auto_create = self.pr_model.create({ + self.rule_1 = self.rule_obj.create({ 'name': 'rule with autocreate', + 'route_id': route_auto.id, 'auto_create_group': True, - 'action': [], + 'action': 'move', + 'warehouse_id': self.warehouse.id, 'picking_type_id': picking_type_id, + 'location_id': self.location.id, + 'location_src_id': loc_components.id, + }) + route_no_auto = self.route_obj.create({ + 'name': 'Not Auto Create Group', + }) + self.rule_obj.create({ + 'name': 'rule with no autocreate', + 'route_id': route_no_auto.id, + 'auto_create_group': False, + 'action': 'move', + 'warehouse_id': self.warehouse.id, + 'picking_type_id': picking_type_id, + 'location_id': self.location.id, + 'location_src_id': loc_components.id, }) - def test_auto_create_group(self): + # Prepare products: + self.prod_auto = self.product_obj.create({ + 'name': 'Test Product 1', + 'type': 'product', + 'route_ids': [(6, 0, [route_auto.id])], + }) + self.prod_no_auto = self.product_obj.create({ + 'name': 'Test Product 2', + 'type': 'product', + 'route_ids': [(6, 0, [route_no_auto.id])], + }) + + def _procure(self, product): + values = {} + self.group_obj.run( + product, 5.0, product.uom_id, self.location, + 'TEST', 'odoo tests', values, + ) + return True + + def test_01_no_auto_create_group(self): """Test auto creation of group.""" - proc1 = self.po_model.create({ - 'name': 'proc01', - 'product_id': self.product_12.id, - 'product_qty': 1.0, - 'product_uom': self.product_12.uom_id.id, - 'rule_id': self.no_auto_create.id, - }) - self.assertFalse(proc1.group_id, - "Procurement Group should not have been assigned.") - proc2 = self.po_model.create({ - 'name': 'proc02', - 'product_id': self.product_12.id, - 'product_qty': 1.0, - 'product_uom': self.product_12.uom_id.id, - 'rule_id': self.auto_create.id, - }) - self.assertTrue(proc2.group_id, - "Procurement Group has not been assigned.") + move = self.move_obj.search([ + ('product_id', '=', self.prod_no_auto.id)]) + self.assertFalse(move) + self._procure(self.prod_no_auto) + move = self.move_obj.search([ + ('product_id', '=', self.prod_no_auto.id)]) + self.assertTrue(move) + self.assertFalse( + move.group_id, "Procurement Group should not have been assigned.") - def test_onchange_method(self): + def test_02_auto_create_group(self): + move = self.move_obj.search([('product_id', '=', self.prod_auto.id)]) + self.assertFalse(move) + self._procure(self.prod_auto) + move = self.move_obj.search([('product_id', '=', self.prod_auto.id)]) + self.assertTrue(move) + self.assertTrue(move.group_id, "Procurement Group not assigned.") + + def test_03_onchange_method(self): """Test onchange method for procurement rule.""" - proc_rule = self.auto_create + proc_rule = self.rule_1 + self.assertTrue(proc_rule.auto_create_group) proc_rule.write({'group_propagation_option': 'none'}) proc_rule._onchange_group_propagation_option() self.assertFalse(proc_rule.auto_create_group) diff --git a/procurement_auto_create_group/views/procurement_view.xml b/procurement_auto_create_group/views/procurement_view.xml index 05d05d679..2eeaa26ac 100644 --- a/procurement_auto_create_group/views/procurement_view.xml +++ b/procurement_auto_create_group/views/procurement_view.xml @@ -2,10 +2,9 @@ - procurement.rule.form + procurement.rule.form - procurement_auto_create_group procurement.rule - +