Merge lp:~numerigraphe-team/purchase-wkfl/7.0-add-purchase_budget_limit into lp:~purchase-core-editors/purchase-wkfl/7.0

Proposed by Lionel Sausin - Initiatives/Numérigraphe
Status: Rejected
Rejected by: Leonardo Pistone
Proposed branch: lp:~numerigraphe-team/purchase-wkfl/7.0-add-purchase_budget_limit
Merge into: lp:~purchase-core-editors/purchase-wkfl/7.0
Diff against target: 569 lines (+511/-0)
11 files modified
purchase_budget_limit/__init__.py (+22/-0)
purchase_budget_limit/__openerp__.py (+54/-0)
purchase_budget_limit/i18n/fr.po (+74/-0)
purchase_budget_limit/i18n/purchase_budget_limit.pot (+74/-0)
purchase_budget_limit/purchase.py (+116/-0)
purchase_budget_limit/purchase_view.xml (+31/-0)
purchase_budget_limit/purchase_workflow.xml (+34/-0)
purchase_budget_limit/security/ir.model.access.csv (+3/-0)
purchase_budget_limit/wizard/__init__.py (+21/-0)
purchase_budget_limit/wizard/purchase_budget.py (+62/-0)
purchase_budget_limit/wizard/purchase_budget_view.xml (+20/-0)
To merge this branch: bzr merge lp:~numerigraphe-team/purchase-wkfl/7.0-add-purchase_budget_limit
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Resubmitting
Loïc Bellier - Numérigraphe (community) code review Approve
Romain Deheele - Camptocamp (community) code review, test Needs Fixing
Review via email: mp+219829@code.launchpad.net

Description of the change

Here is a new module to block purchase orders when the budget is at risk of being exhausted.

Only validated budgets are checked.
Also, only invoiced purchases are counted (because only invoices are counted in the budget). I'll soon be publishing an additional module to count draft purchases in the budgets too.

Unfortunately, no automatic test bundled because the account_budget does not provide any either.

To post a comment you must log in.
Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Hi,

Several flake8 suggestions:

7.0-add-purchase_budget_limit/purchase_budget_limit/purchase.py:69:25: E128 continuation line under-indented for visual indent
7.0-add-purchase_budget_limit/purchase_budget_limit/purchase.py:76:30: E128 continuation line under-indented for visual indent
7.0-add-purchase_budget_limit/purchase_budget_limit/purchase.py:79:37: E127 continuation line over-indented for visual indent
7.0-add-purchase_budget_limit/purchase_budget_limit/purchase.py:80:20: E122 continuation line missing indentation or outdented
7.0-add-purchase_budget_limit/purchase_budget_limit/wizard/purchase_budget.py:42:13: E128 continuation line under-indented for visual indent
7.0-add-purchase_budget_limit/purchase_budget_limit/wizard/purchase_budget.py:61:6: E121 continuation line indentation is not a multiple of four

review: Needs Fixing (code review)
35. By Numérigraphe

[REF] PEP8

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

PEP8 compliance fixed.

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Thanks, other details:

-l.454 s/dificulties/difficulties

-Maybe you could precise that we need to check "Analytic accounting for purchases" in settings/configuration/Purchases or check it directly during addon install.

Otherwise, it seems ok.

Romain

review: Needs Fixing (code review, test)
Revision history for this message
Loïc Bellier - Numérigraphe (lb-b) wrote :

Ok for me too !

review: Approve (code review)
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Thanks Romain, I fixed it. Not sure why account_budget does not activate analytic accounting on sales & purchase, I don't think you can enter a budget without that.
So I only added in the module description

36. By Numérigraphe

[IMP] Translation (template and French)

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

This project is now hosted on https://github.com/OCA/purchase-workflow. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Proposal moved to github: https://github.com/OCA/purchase-workflow/pull/38/files
Please reject this MP on Launchpad to make it clear we won't merge it here.

Unmerged revisions

36. By Numérigraphe

[IMP] Translation (template and French)

35. By Numérigraphe

[REF] PEP8

34. By Numérigraphe

[ADD] purchase_budget_limit: new module to block purchase orders when the budget is at risk of being exhausted

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'purchase_budget_limit'
=== added file 'purchase_budget_limit/__init__.py'
--- purchase_budget_limit/__init__.py 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/__init__.py 2014-07-02 13:10:24 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19##############################################################################
20
21from . import wizard
22from . import purchase
023
=== added file 'purchase_budget_limit/__openerp__.py'
--- purchase_budget_limit/__openerp__.py 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/__openerp__.py 2014-07-02 13:10:24 +0000
@@ -0,0 +1,54 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19##############################################################################
20
21{
22 'name': "Block over-budget Purchase Orders",
23 'version': '1.1',
24 'author': u'Numérigraphe SARL',
25 'category': 'Purchase Management',
26 'description': '''
27Let Budget managers define limits on Purchase Orders
28====================================================
29
30When new Purchase Orders are being confirmed, this module will put them in a
31special state if the remaining budget is not sufficient to pay the expected
32invoice in one of the Budget Lines in the same period.
33
34Purchase managers can :
35- either wait until the financial situation changes
36- or override the budget and approve the Purchase Order
37- or cancel the Purchase Order.
38''',
39 'depends': ['account_budget', 'purchase'],
40 'data': [
41 'purchase_workflow.xml',
42 'purchase_view.xml',
43 'wizard/purchase_budget_view.xml',
44 'security/ir.model.access.csv',
45 ],
46 'test': [
47 # TODO add an automatic test:
48 # - create a budget line for 10000 EUR
49 # - create a PO for 100 EUR and validate it, check it's not blocked
50 # - create a budget line for 150 EUR
51 # - create a PO for 200 EUR and validate it, check it's blocked
52 # - override the budget and check the PO is validated
53 ]
54}
055
=== added directory 'purchase_budget_limit/i18n'
=== added file 'purchase_budget_limit/i18n/fr.po'
--- purchase_budget_limit/i18n/fr.po 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/i18n/fr.po 2014-07-02 13:10:24 +0000
@@ -0,0 +1,74 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * purchase_budget_limit
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-07-02 13:00+0000\n"
10"PO-Revision-Date: 2014-07-02 13:00+0000\n"
11"Last-Translator: <>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: \n"
16"Plural-Forms: \n"
17
18#. module: purchase_budget_limit
19#: view:purchase.budget.wizard:0
20msgid "Block Purchase Order"
21msgstr "Bloquer les commandes d'achat"
22
23#. module: purchase_budget_limit
24#: field:purchase.budget.wizard,budget_line_ids:0
25msgid "Budget Lines"
26msgstr "Lignes budgétaires"
27
28#. module: purchase_budget_limit
29#: code:addons/purchase_budget_limit/purchase.py:105
30#: view:purchase.budget.wizard:0
31#, python-format
32msgid "Budget warning"
33msgstr "Avertissement budgétaire"
34
35#. module: purchase_budget_limit
36#: view:purchase.order:0
37msgid "Cancel Order"
38msgstr "Annuler la commande"
39
40#. module: purchase_budget_limit
41#: view:purchase.budget.wizard:0
42#: view:purchase.order:0
43msgid "Override Budgets"
44msgstr "Outrepasser les budgets"
45
46#. module: purchase_budget_limit
47#: code:_description:0
48#: model:ir.model,name:purchase_budget_limit.model_purchase_order
49#, python-format
50msgid "Purchase Order"
51msgstr "Commande d'achat"
52
53#. module: purchase_budget_limit
54#: view:purchase.budget.wizard:0
55msgid "The following Budget Lines will be exhausted if you confirm the Purchase Order: you may have dificulties paying the Supplier Invoice."
56msgstr "Les lignes de budget suivantes seront épuisées si vous confirmez cette commande : il vous sera peut-être difficile de payer la facture d'achat."
57
58#. module: purchase_budget_limit
59#: view:purchase.order:0
60msgid "button_confirm"
61msgstr "button_confirm"
62
63#. module: purchase_budget_limit
64#: view:purchase.order:0
65msgid "object"
66msgstr "object"
67
68#. module: purchase_budget_limit
69#: code:_description:0
70#: model:ir.model,name:purchase_budget_limit.model_purchase_budget_wizard
71#, python-format
72msgid "purchase.budget.wizard"
73msgstr "purchase.budget.wizard"
74
075
=== added file 'purchase_budget_limit/i18n/purchase_budget_limit.pot'
--- purchase_budget_limit/i18n/purchase_budget_limit.pot 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/i18n/purchase_budget_limit.pot 2014-07-02 13:10:24 +0000
@@ -0,0 +1,74 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * purchase_budget_limit
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-07-02 13:00+0000\n"
10"PO-Revision-Date: 2014-07-02 13:00+0000\n"
11"Last-Translator: <>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: \n"
16"Plural-Forms: \n"
17
18#. module: purchase_budget_limit
19#: view:purchase.budget.wizard:0
20msgid "Block Purchase Order"
21msgstr ""
22
23#. module: purchase_budget_limit
24#: field:purchase.budget.wizard,budget_line_ids:0
25msgid "Budget Lines"
26msgstr ""
27
28#. module: purchase_budget_limit
29#: code:addons/purchase_budget_limit/purchase.py:105
30#: view:purchase.budget.wizard:0
31#, python-format
32msgid "Budget warning"
33msgstr ""
34
35#. module: purchase_budget_limit
36#: view:purchase.order:0
37msgid "Cancel Order"
38msgstr ""
39
40#. module: purchase_budget_limit
41#: view:purchase.budget.wizard:0
42#: view:purchase.order:0
43msgid "Override Budgets"
44msgstr ""
45
46#. module: purchase_budget_limit
47#: code:_description:0
48#: model:ir.model,name:purchase_budget_limit.model_purchase_order
49#, python-format
50msgid "Purchase Order"
51msgstr ""
52
53#. module: purchase_budget_limit
54#: view:purchase.budget.wizard:0
55msgid "The following Budget Lines will be exhausted if you confirm the Purchase Order: you may have dificulties paying the Supplier Invoice."
56msgstr ""
57
58#. module: purchase_budget_limit
59#: view:purchase.order:0
60msgid "button_confirm"
61msgstr ""
62
63#. module: purchase_budget_limit
64#: view:purchase.order:0
65msgid "object"
66msgstr ""
67
68#. module: purchase_budget_limit
69#: code:_description:0
70#: model:ir.model,name:purchase_budget_limit.model_purchase_budget_wizard
71#, python-format
72msgid "purchase.budget.wizard"
73msgstr ""
74
075
=== added file 'purchase_budget_limit/purchase.py'
--- purchase_budget_limit/purchase.py 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/purchase.py 2014-07-02 13:10:24 +0000
@@ -0,0 +1,116 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19##############################################################################
20
21import time
22
23from openerp import netsvc
24from openerp.osv import orm
25from openerp.tools.translate import _
26
27
28class PurchaseOrder (orm.Model):
29 """Display a warning when confirming a Purchase if the budget is too low"""
30 _inherit = 'purchase.order'
31
32 # Initialization (no context)
33 def __init__(self, pool, cr):
34 """
35 Add a new state value.
36
37 Doing it in __init__ is cleaner than copying and pasting the field
38 definition in _columns and should be compatible with future/customized
39 versions.
40 """
41 super(PurchaseOrder, self).__init__(pool, cr)
42 super(PurchaseOrder, self).STATE_SELECTION.append(
43 ('over_budget', 'Over Budget'))
44
45 # Workflow Action methods (no context)
46 def wkf_over_budget(self, cr, uid, ids):
47 """Change the Purchase Order's state to 'Over Budget'"""
48 self.write(cr, uid, ids, {'state': 'over_budget'})
49 return True
50
51 # Model methods (context except when called by the Workflow Engine)
52 def exhausted_budget_lines(self, cr, uid, ids, context=None):
53 """
54 Find the Budget Line which do not have enough funds left to pay the POs
55
56 @return: IDs of the Budget Lines
57 """
58 if not isinstance(ids, list):
59 ids = [ids]
60
61 budget_line_ids = set()
62 b_line_obj = self.pool['crossovered.budget.lines']
63 today = time.strftime('%Y-%m-%d')
64 for po_id in ids:
65 for ol in self.browse(cr, uid, po_id, context=context).order_line:
66 if ol.account_analytic_id:
67 # should we check sub-accounts too?
68 bl_ids = b_line_obj.search(
69 cr, uid,
70 [('analytic_account_id',
71 '=', ol.account_analytic_id.id),
72 ('date_from', '<=', today),
73 ('date_to', '>=', today)],
74 context=context)
75 budget_line_ids.update(
76 [l.id for l in b_line_obj.browse(
77 cr, uid, bl_ids, context=context)
78 if l.crossovered_budget_id.state == 'validate'
79 and (l.practical_amount - ol.price_subtotal
80 < l.theoritical_amount)])
81 return list(budget_line_ids)
82
83 def button_confirm(self, cr, uid, ids, context=None):
84 """Advance the workflow and pop up a message on 'Over Budget' state.
85
86 @return: True if all orders are OK, or an client action dictionary to
87 open a confirmation wizard if any order is over-budget.
88 """
89 if context is None:
90 context = {}
91 if not isinstance(ids, list):
92 ids = [ids]
93
94 # Send the workflow signal on every purchase order
95 wf_service = netsvc.LocalService("workflow")
96 for po_id in ids:
97 wf_service.trg_validate(
98 uid, self._name, po_id, 'purchase_confirm', cr)
99
100 # Return True or an Action dictionary
101 orders_ok = all([o.state != 'over_budget'
102 for o in self.browse(cr, uid, ids, context=context)])
103
104 return orders_ok or {
105 'name': _('Budget warning'),
106 'type': 'ir.actions.act_window',
107 'res_model': 'purchase.budget.wizard',
108 'view_type': 'form',
109 'view_mode': 'form',
110 'target': 'new',
111 'nodestroy': True,
112 'context': dict(context,
113 active_model='purchase.order',
114 active_ids=ids,
115 active_id=ids[0])
116 }
0117
=== added file 'purchase_budget_limit/purchase_view.xml'
--- purchase_budget_limit/purchase_view.xml 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/purchase_view.xml 2014-07-02 13:10:24 +0000
@@ -0,0 +1,31 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <!-- Adapt the buttons in the form view to handle the new workflow and the state "Over Budget" -->
5 <record id="purchase_order_form_over_budget" model="ir.ui.view">
6 <field name="name">purchase.order.form.over_budget</field>
7 <field name="inherit_id" ref="purchase.purchase_order_form" />
8 <field name="model">purchase.order</field>
9 <field name="arch" type="xml">
10 <data>
11 <!-- Tweak the button "Confirm" to start a wizard when Budget Lines are exhausted -->
12 <xpath expr="//button[@name='purchase_confirm']" position="attributes">
13 <attribute name="name">button_confirm</attribute>
14 <attribute name="type">object</attribute>
15 </xpath>
16 <!-- Add a button to confirm over-budget POs
17 Let users cancel over-budget POs -->
18 <xpath expr="//button[@name='purchase_cancel']" position="after">
19 <button name="purchase_cancel" states="over_budget" string="Cancel Order"/>
20 <button name="purchase_confirm_overbudget" states="over_budget" string="Override Budgets" class="oe_highlight"/>
21 </xpath>
22 </data>
23 </field>
24 </record>
25
26 <!-- Add the state "Over Budget" to the "Draft" search filter and list -->
27 <record id="purchase.purchase_rfq" model="ir.actions.act_window">
28 <field name="domain">[('state','in',('draft','sent','confirmed','over_budget'))]</field>
29 </record>
30 </data>
31</openerp>
032
=== added file 'purchase_budget_limit/purchase_workflow.xml'
--- purchase_budget_limit/purchase_workflow.xml 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/purchase_workflow.xml 2014-07-02 13:10:24 +0000
@@ -0,0 +1,34 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <!-- New activity for purchase orders when Budget Lines are exhausted -->
5 <!-- Whenever a PO is Over-budget, the signal "purchase_confirm_overbudget" must be sent to override -->
6 <record id="act_over_budget" model="workflow.activity">
7 <field name="wkf_id" ref="purchase.purchase_order" />
8 <field name="name">over_budget</field>
9 <field name="kind">function</field>
10 <field name="action">wkf_over_budget()</field>
11 </record>
12 <record id="trans_draft_over_budget" model="workflow.transition">
13 <field name="act_from" ref="purchase.act_draft"/>
14 <field name="act_to" ref="act_over_budget"/>
15 <field name="signal">purchase_confirm</field>
16 <field name="condition">exhausted_budget_lines()</field>
17 </record>
18 <record id="trans_over_budget_confirm" model="workflow.transition">
19 <field name="act_from" ref="act_over_budget"/>
20 <field name="act_to" ref="purchase.act_confirmed"/>
21 <field name="signal">purchase_confirm_overbudget</field>
22 </record>
23 <record id="trans_over_budget_cancel" model="workflow.transition">
24 <field name="act_from" ref="act_over_budget"/>
25 <field name="act_to" ref="purchase.act_cancel"/>
26 <field name="signal">purchase_cancel</field>
27 </record>
28
29 <!-- only move from draft to confirm if budgets are OK -->
30 <record id="purchase.trans_draft_confirmed" model="workflow.transition">
31 <field name="condition">not exhausted_budget_lines()</field>
32 </record>
33 </data>
34</openerp>
035
=== added directory 'purchase_budget_limit/security'
=== added file 'purchase_budget_limit/security/ir.model.access.csv'
--- purchase_budget_limit/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/security/ir.model.access.csv 2014-07-02 13:10:24 +0000
@@ -0,0 +1,3 @@
1id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2access_budget_purchase_user,Purchase users can read budgets,account_budget.model_crossovered_budget_lines,purchase.group_purchase_user,1,0,0,0
3access_budget_purchase_user_manager,Purchase managers can read budgets,account_budget.model_crossovered_budget_lines,purchase.group_purchase_manager,1,0,0,0
04
=== added directory 'purchase_budget_limit/wizard'
=== added file 'purchase_budget_limit/wizard/__init__.py'
--- purchase_budget_limit/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/wizard/__init__.py 2014-07-02 13:10:24 +0000
@@ -0,0 +1,21 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# This module is copyright (C) 2011 Numérigraphe SARL. All Rights Reserved.
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19##############################################################################
20
21from . import purchase_budget
022
=== added file 'purchase_budget_limit/wizard/purchase_budget.py'
--- purchase_budget_limit/wizard/purchase_budget.py 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/wizard/purchase_budget.py 2014-07-02 13:10:24 +0000
@@ -0,0 +1,62 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19##############################################################################
20
21import openerp.netsvc as netsvc
22from openerp.osv import fields, osv
23
24
25class PurchaseBudget(osv.TransientModel):
26 _name = 'purchase.budget.wizard'
27 _columns = {
28 'budget_line_ids': fields.many2many("crossovered.budget.lines",
29 rel='purchase_budget_lines_rel',
30 id1='order_id', id2='line_id',
31 string='Budget Lines',
32 readonly=True),
33 }
34
35 def _get_budget_line_ids(self, cr, uid, context=None):
36 """Load the exhausted budget lines related to the Purchase Orders"""
37 if context is None:
38 context = {}
39 if context.get('active_model') != 'purchase.order':
40 return []
41 return self.pool['purchase.order'].exhausted_budget_lines(
42 cr, uid, context.get('active_ids'), context=context)
43
44 def override_budget(self, cr, uid, ids, context=None):
45 """Override the Budgets and confirm the Purchase Order"""
46 if context is None:
47 context = {}
48 if context.get('active_model') != 'purchase.order':
49 return False
50
51 # Send the workflow signal on every purchase order
52 wf_service = netsvc.LocalService("workflow")
53 for po_id in context.get('active_ids'):
54 wf_service.trg_validate(
55 uid, 'purchase.order', po_id, 'purchase_confirm_overbudget',
56 cr)
57 return {'type': 'ir.actions.act_window_close'}
58
59 _defaults = {
60 'budget_line_ids': _get_budget_line_ids
61 }
62PurchaseBudget()
063
=== added file 'purchase_budget_limit/wizard/purchase_budget_view.xml'
--- purchase_budget_limit/wizard/purchase_budget_view.xml 1970-01-01 00:00:00 +0000
+++ purchase_budget_limit/wizard/purchase_budget_view.xml 2014-07-02 13:10:24 +0000
@@ -0,0 +1,20 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<openerp>
3 <data>
4 <record id="purchase_budget_wizard_form" model="ir.ui.view">
5 <field name="name">purchase.budget.wizard.form</field>
6 <field name="model">purchase.budget.wizard</field>
7 <field name="type">form</field>
8 <field name="arch" type="xml">
9 <form string="Budget warning" version="7.0">
10 <label string="The following Budget Lines will be exhausted if you confirm the Purchase Order: you may have dificulties paying the Supplier Invoice."/>
11 <field name="budget_line_ids" nolabel="1"/>
12 <footer>
13 <button special="cancel" string="Block Purchase Order" class="oe_highlight"/>
14 <button name="override_budget" string="Override Budgets" type="object"/>
15 </footer>
16 </form>
17 </field>
18 </record>
19 </data>
20</openerp>

Subscribers

People subscribed via source and target branches