From 2a92eb09671b9723240526b7ecfcebb68ee01988 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Thu, 23 Nov 2017 12:08:41 +0100 Subject: [PATCH] refactoring --- oca_dependencies.txt | 2 + purchase_order_approval_block/__init__.py | 4 +- purchase_order_approval_block/__manifest__.py | 7 +-- .../data/purchase_exception_data.xml | 16 +++++++ .../models/__init__.py | 3 -- .../models/purchase_approval_block_reason.py | 3 +- .../models/purchase_order.py | 17 +------ ...purchase_order_approval_block_security.xml | 1 - .../tests/__init__.py | 3 -- .../tests/test_po_approval_block_reason.py | 46 +++++++++++++++---- .../test_purchase_order_approval_block.py | 9 +--- .../purchase_approval_block_reason_view.xml | 1 - .../views/purchase_order_view.xml | 1 - .../wizard/__init__.py | 2 + .../wizard/purchase_exception_confirm.py | 15 ++++++ 15 files changed, 80 insertions(+), 50 deletions(-) create mode 100644 oca_dependencies.txt create mode 100644 purchase_order_approval_block/data/purchase_exception_data.xml create mode 100644 purchase_order_approval_block/wizard/__init__.py create mode 100644 purchase_order_approval_block/wizard/purchase_exception_confirm.py diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 00000000000..91aa0386347 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1,2 @@ +server-tools https://github.com/akretion/server-tools 11.0-mig-base_exception +purchase-worfkflow https://github.com/Eficent/purchase-workflow 11.0-purchase_exception-imp diff --git a/purchase_order_approval_block/__init__.py b/purchase_order_approval_block/__init__.py index 15ed7800f19..0217b0f920b 100644 --- a/purchase_order_approval_block/__init__.py +++ b/purchase_order_approval_block/__init__.py @@ -1,5 +1,3 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# Copyright 2017 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models +from . import wizard diff --git a/purchase_order_approval_block/__manifest__.py b/purchase_order_approval_block/__manifest__.py index c93b2d7ce2a..ee7393279b9 100644 --- a/purchase_order_approval_block/__manifest__.py +++ b/purchase_order_approval_block/__manifest__.py @@ -1,17 +1,18 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. -# Copyright 2017 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Purchase Order Approval Block", - "author": "Eficent, SerpentCS, Odoo Community Association (OCA)", + "author": "Eficent, Odoo Community Association (OCA)", "version": "11.0.1.0.0", "category": "Purchase Management", "website": "https://github.com/OCA/purchase-workflow", "depends": [ 'purchase', + 'purchase_exception', ], "data": [ + 'data/purchase_exception_data.xml', 'security/ir.model.access.csv', 'security/purchase_order_approval_block_security.xml', 'views/purchase_approval_block_reason_view.xml', diff --git a/purchase_order_approval_block/data/purchase_exception_data.xml b/purchase_order_approval_block/data/purchase_exception_data.xml new file mode 100644 index 00000000000..63a1964f014 --- /dev/null +++ b/purchase_order_approval_block/data/purchase_exception_data.xml @@ -0,0 +1,16 @@ + + + + + Approval Blocked + The approval has been blocked, + with a Blocking reason. + 100 + purchase + purchase.order + if 'approval_block_id' in purchase._fields and purchase.approval_block_id: failed = True + to approve + + + + diff --git a/purchase_order_approval_block/models/__init__.py b/purchase_order_approval_block/models/__init__.py index 8e7b64c3b8a..48ef24d0bb2 100644 --- a/purchase_order_approval_block/models/__init__.py +++ b/purchase_order_approval_block/models/__init__.py @@ -1,6 +1,3 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# Copyright 2017 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import purchase_approval_block_reason from . import purchase_order diff --git a/purchase_order_approval_block/models/purchase_approval_block_reason.py b/purchase_order_approval_block/models/purchase_approval_block_reason.py index b6240bdab82..9df886a2170 100644 --- a/purchase_order_approval_block/models/purchase_approval_block_reason.py +++ b/purchase_order_approval_block/models/purchase_approval_block_reason.py @@ -1,6 +1,5 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. -# Copyright 2017 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models diff --git a/purchase_order_approval_block/models/purchase_order.py b/purchase_order_approval_block/models/purchase_order.py index 2e971be3ffd..796027474fb 100644 --- a/purchase_order_approval_block/models/purchase_order.py +++ b/purchase_order_approval_block/models/purchase_order.py @@ -1,6 +1,5 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. -# Copyright 2017 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models, _ @@ -54,18 +53,6 @@ def button_approve(self, force=False): @api.multi def button_release_approval_block(self): - for order in self.with_context(force_po_approval_block_release=True): + for order in self: order.approval_block_id = False return True - - @api.multi - def _check_order_release(self): - self.ensure_one() - if self.approval_block_id: - return True - - @api.multi - def button_confirm(self): - self.filtered(lambda o: o.state in ['draft', 'sent'] and - o.approval_blocked).write({'state': 'to approve'}) - return super(PurchaseOrder, self).button_confirm() diff --git a/purchase_order_approval_block/security/purchase_order_approval_block_security.xml b/purchase_order_approval_block/security/purchase_order_approval_block_security.xml index 36cbd7e4e97..ddb3fa6afaa 100644 --- a/purchase_order_approval_block/security/purchase_order_approval_block_security.xml +++ b/purchase_order_approval_block/security/purchase_order_approval_block_security.xml @@ -2,7 +2,6 @@ diff --git a/purchase_order_approval_block/tests/__init__.py b/purchase_order_approval_block/tests/__init__.py index 755befe9913..b291c5c330b 100644 --- a/purchase_order_approval_block/tests/__init__.py +++ b/purchase_order_approval_block/tests/__init__.py @@ -1,6 +1,3 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# Copyright 2017 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_purchase_order_approval_block from . import test_po_approval_block_reason diff --git a/purchase_order_approval_block/tests/test_po_approval_block_reason.py b/purchase_order_approval_block/tests/test_po_approval_block_reason.py index a45fa4762e6..650b6af3ade 100644 --- a/purchase_order_approval_block/tests/test_po_approval_block_reason.py +++ b/purchase_order_approval_block/tests/test_po_approval_block_reason.py @@ -1,6 +1,5 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. -# Copyright 2017 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo.addons.purchase_order_approval_block.tests.\ test_purchase_order_approval_block import TestPurchaseOrderApprovalBlock @@ -10,18 +9,45 @@ class TestPoApprovalBlockReason(TestPurchaseOrderApprovalBlock): def test_po_approval_block_manual_release(self): """Confirming the Blocked PO""" + # Create a PO + purchase = self._create_purchase( + [(self.product1, 1), + (self.product2, 5), + (self.product3, 8)]) + + purchase.approval_block_id = self.po_approval_block_reason.id + + self.assertEqual(purchase.approval_blocked, True) # The purchase manager unblocks the RFQ with block - self.purchase1.sudo(self.user2_id).button_release_approval_block() - self.assertEquals(self.purchase1.approval_block_id, self.env[ + purchase.sudo(self.user2_id).button_release_approval_block() + self.assertEqual(purchase.approval_block_id, self.env[ 'purchase.approval.block.reason']) # The purchase user validates the RFQ without block - self.purchase1.sudo(self.user1_id).button_confirm() + purchase.sudo(self.user1_id).button_confirm() # The PO is approved - self.assertEquals(self.purchase1.state, 'purchase') + self.assertEqual(purchase.state, 'purchase') def test_po_approval_block_to_approve_release(self): + # Create a PO + purchase = self._create_purchase( + [(self.product1, 1), + (self.product2, 5), + (self.product3, 8)]) + + purchase.approval_block_id = self.po_approval_block_reason.id # The purchase user validates the RFQ with block, and is now to approve - self.purchase1.sudo(self.user2_id).button_confirm() - self.assertEquals(self.purchase1.state, 'to approve') - self.purchase1.sudo(self.user2_id).button_approve(force=False) - self.assertEquals(self.purchase1.state, 'purchase') + purchase.sudo(self.user2_id).button_confirm() + self.assertEquals(purchase.state, 'to approve') + + # Simulation the opening of the wizard purchase_exception_confirm and + # set ignore_exception to True + po_except_confirm = \ + self.env['purchase.exception.confirm'].with_context( + { + 'active_id': purchase.id, + 'active_ids': [purchase.id], + 'active_model': purchase._name + }).create({'ignore': True}) + po_except_confirm.action_confirm() + + self.assertEqual(purchase.state, 'purchase') diff --git a/purchase_order_approval_block/tests/test_purchase_order_approval_block.py b/purchase_order_approval_block/tests/test_purchase_order_approval_block.py index 328f3c173d9..ae6a9b2347f 100644 --- a/purchase_order_approval_block/tests/test_purchase_order_approval_block.py +++ b/purchase_order_approval_block/tests/test_purchase_order_approval_block.py @@ -1,6 +1,5 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. -# Copyright 2017 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). import time from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT @@ -35,11 +34,6 @@ def setUp(self): self.company1) # Create a PO Block Reason self._create_block_reason() - # Create a PO - self.purchase1 = self._create_purchase( - [(self.product1, 1), - (self.product2, 5), - (self.product3, 8)]) def _create_block_reason(self): self.po_approval_block_reason = self.po_block_obj.create({ @@ -80,7 +74,6 @@ def _create_purchase(self, line_products): lines.append((0, 0, line_values)) purchase = self.po_obj.create({ 'partner_id': self.partner1.id, - 'approval_block_id': self.po_approval_block_reason.id, 'order_line': lines, 'company_id': self.company1.id, }) diff --git a/purchase_order_approval_block/views/purchase_approval_block_reason_view.xml b/purchase_order_approval_block/views/purchase_approval_block_reason_view.xml index cc06cb78f53..3fe9af23225 100644 --- a/purchase_order_approval_block/views/purchase_approval_block_reason_view.xml +++ b/purchase_order_approval_block/views/purchase_approval_block_reason_view.xml @@ -2,7 +2,6 @@ diff --git a/purchase_order_approval_block/views/purchase_order_view.xml b/purchase_order_approval_block/views/purchase_order_view.xml index a3a69fb9863..0fc67934f53 100644 --- a/purchase_order_approval_block/views/purchase_order_view.xml +++ b/purchase_order_approval_block/views/purchase_order_view.xml @@ -2,7 +2,6 @@ diff --git a/purchase_order_approval_block/wizard/__init__.py b/purchase_order_approval_block/wizard/__init__.py new file mode 100644 index 00000000000..a96153cbfac --- /dev/null +++ b/purchase_order_approval_block/wizard/__init__.py @@ -0,0 +1,2 @@ + +from . import purchase_exception_confirm diff --git a/purchase_order_approval_block/wizard/purchase_exception_confirm.py b/purchase_order_approval_block/wizard/purchase_exception_confirm.py new file mode 100644 index 00000000000..6a60837f04f --- /dev/null +++ b/purchase_order_approval_block/wizard/purchase_exception_confirm.py @@ -0,0 +1,15 @@ +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class PurchaseExceptionConfirm(models.TransientModel): + _inherit = 'purchase.exception.confirm' + + @api.multi + def action_confirm(self): + self.ensure_one() + if self.ignore and self.related_model_id.approval_block_id: + self.related_model_id.button_release_approval_block() + return super(PurchaseExceptionConfirm, self).action_confirm()