Skip to content

Commit

Permalink
[MIG] purchase_order_block: Migration to 11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rgarnau authored and JordiBForgeFlow committed Jan 9, 2018
1 parent dde8fd5 commit 864de85
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 71 deletions.
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
server-tools
purchase-worfkflow
10 changes: 8 additions & 2 deletions purchase_order_approval_block/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:alt: License LGPL-3
:target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License LGPL-3

=============================
Purchase Order Approval Block
Expand Down Expand Up @@ -58,7 +59,7 @@ set or released.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/142/10.0
:target: https://runbot.odoo-community.org/runbot/142/11.0

Bug Tracker
===========
Expand All @@ -71,6 +72,11 @@ help us smashing it by providing a detailed and welcomed feedback.
Credits
=======

Images
------

* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.

Contributors
------------

Expand Down
5 changes: 1 addition & 4 deletions purchase_order_approval_block/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
# 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
10 changes: 5 additions & 5 deletions purchase_order_approval_block/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# -*- coding: utf-8 -*-
# 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)",
"version": "10.0.1.0.0",
"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>
4 changes: 0 additions & 4 deletions purchase_order_approval_block/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# 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,7 +1,5 @@
# -*- coding: utf-8 -*-
# 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
18 changes: 2 additions & 16 deletions purchase_order_approval_block/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# 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 @@ -55,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
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
Copyright 2017 Serpent Consulting Services Pvt. Ltd.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<!--
Copyright 2017 Eficent Business and IT Consulting Services S.L.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
-->

<odoo>
<record id="group_rfq_approval_block" model="res.groups">
Expand Down
4 changes: 0 additions & 4 deletions purchase_order_approval_block/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# 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,7 +1,5 @@
# -*- coding: utf-8 -*-
# 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 @@ -11,18 +9,61 @@ 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_01(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
purchase.sudo(self.user2_id).button_confirm()
self.assertEquals(purchase.state, 'to approve')

def test_po_approval_block_to_approve_release(self):
# 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')

def test_po_approval_block_to_approve_release_02(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')

purchase.sudo(self.user2_id).button_approve()

self.assertEqual(purchase.state, 'purchase')
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# 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 @@ -36,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 @@ -81,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
@@ -1,15 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
Copyright 2017 Serpent Consulting Services Pvt. Ltd.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<!--
Copyright 2017 Eficent Business and IT Consulting Services S.L.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
-->

<odoo>
<record id="purchase_approval_block_reason_tree_view" model="ir.ui.view">
<field name="name">purchase.approval.block.reason.tree</field>
<field name="model">purchase.approval.block.reason</field>
<field name="arch" type="xml">
<tree string="Purchase Order Approval Block Reason">
<tree string="Purchase Order Approval Block Reasons">
<field name="name"/>
<field name="description"/>
</tree>
Expand Down Expand Up @@ -38,12 +39,12 @@
</field>
</record>
<act_window id="action_purchase_approval_block_reason"
name="Purchase Approval Block Reason"
name="Purchase Approval Block Reasons"
res_model="purchase.approval.block.reason"
view_mode="tree,form"/>

<menuitem id="menu_purchase_approval_block_reason"
name="Purchase Approval Block Reason"
name="Purchase Approval Block Reasons"
parent="purchase.menu_purchase_config"
action="action_purchase_approval_block_reason"/>
</odoo>
7 changes: 4 additions & 3 deletions purchase_order_approval_block/views/purchase_order_view.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
Copyright 2017 Serpent Consulting Services Pvt. Ltd.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<!--
Copyright 2017 Eficent Business and IT Consulting Services S.L.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
-->

<odoo>
<record id="purchase_order_form" model="ir.ui.view">
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 864de85

Please sign in to comment.