Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBForgeFlow committed Nov 23, 2017
1 parent 3cd38a1 commit 2a92eb0
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 50 deletions.
2 changes: 2 additions & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions purchase_order_approval_block/__init__.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions purchase_order_approval_block/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
16 changes: 16 additions & 0 deletions purchase_order_approval_block/data/purchase_exception_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id ="po_excep_approval_block" model="exception.rule">
<field name="name">Approval Blocked</field>
<field name="description">The approval has been blocked,
with a Blocking reason.</field>
<field name="sequence">100</field>
<field name="rule_group">purchase</field>
<field name="model">purchase.order</field>
<field name="code">if 'approval_block_id' in purchase._fields and purchase.approval_block_id: failed = True</field>
<field name="next_state">to approve</field>
<field name="active" eval="True"/>
</record>

</odoo>
3 changes: 0 additions & 3 deletions purchase_order_approval_block/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

Expand Down
17 changes: 2 additions & 15 deletions purchase_order_approval_block/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -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, _

Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<!--
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).
-->

Expand Down
3 changes: 0 additions & 3 deletions purchase_order_approval_block/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<!--
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).
-->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<!--
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).
-->

Expand Down
2 changes: 2 additions & 0 deletions purchase_order_approval_block/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

from . import purchase_exception_confirm
15 changes: 15 additions & 0 deletions purchase_order_approval_block/wizard/purchase_exception_confirm.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 2a92eb0

Please sign in to comment.