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
1=== added directory 'purchase_budget_limit'
2=== added file 'purchase_budget_limit/__init__.py'
3--- purchase_budget_limit/__init__.py 1970-01-01 00:00:00 +0000
4+++ purchase_budget_limit/__init__.py 2014-07-02 13:10:24 +0000
5@@ -0,0 +1,22 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU Affero General Public License as
13+# published by the Free Software Foundation, either version 3 of the
14+# License, or (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU Affero General Public License for more details.
20+#
21+# You should have received a copy of the GNU Affero General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+##############################################################################
25+
26+from . import wizard
27+from . import purchase
28
29=== added file 'purchase_budget_limit/__openerp__.py'
30--- purchase_budget_limit/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ purchase_budget_limit/__openerp__.py 2014-07-02 13:10:24 +0000
32@@ -0,0 +1,54 @@
33+# -*- coding: utf-8 -*-
34+##############################################################################
35+#
36+# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
37+#
38+# This program is free software: you can redistribute it and/or modify
39+# it under the terms of the GNU Affero General Public License as
40+# published by the Free Software Foundation, either version 3 of the
41+# License, or (at your option) any later version.
42+#
43+# This program is distributed in the hope that it will be useful,
44+# but WITHOUT ANY WARRANTY; without even the implied warranty of
45+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46+# GNU Affero General Public License for more details.
47+#
48+# You should have received a copy of the GNU Affero General Public License
49+# along with this program. If not, see <http://www.gnu.org/licenses/>.
50+#
51+##############################################################################
52+
53+{
54+ 'name': "Block over-budget Purchase Orders",
55+ 'version': '1.1',
56+ 'author': u'Numérigraphe SARL',
57+ 'category': 'Purchase Management',
58+ 'description': '''
59+Let Budget managers define limits on Purchase Orders
60+====================================================
61+
62+When new Purchase Orders are being confirmed, this module will put them in a
63+special state if the remaining budget is not sufficient to pay the expected
64+invoice in one of the Budget Lines in the same period.
65+
66+Purchase managers can :
67+- either wait until the financial situation changes
68+- or override the budget and approve the Purchase Order
69+- or cancel the Purchase Order.
70+''',
71+ 'depends': ['account_budget', 'purchase'],
72+ 'data': [
73+ 'purchase_workflow.xml',
74+ 'purchase_view.xml',
75+ 'wizard/purchase_budget_view.xml',
76+ 'security/ir.model.access.csv',
77+ ],
78+ 'test': [
79+ # TODO add an automatic test:
80+ # - create a budget line for 10000 EUR
81+ # - create a PO for 100 EUR and validate it, check it's not blocked
82+ # - create a budget line for 150 EUR
83+ # - create a PO for 200 EUR and validate it, check it's blocked
84+ # - override the budget and check the PO is validated
85+ ]
86+}
87
88=== added directory 'purchase_budget_limit/i18n'
89=== added file 'purchase_budget_limit/i18n/fr.po'
90--- purchase_budget_limit/i18n/fr.po 1970-01-01 00:00:00 +0000
91+++ purchase_budget_limit/i18n/fr.po 2014-07-02 13:10:24 +0000
92@@ -0,0 +1,74 @@
93+# Translation of OpenERP Server.
94+# This file contains the translation of the following modules:
95+# * purchase_budget_limit
96+#
97+msgid ""
98+msgstr ""
99+"Project-Id-Version: OpenERP Server 7.0\n"
100+"Report-Msgid-Bugs-To: \n"
101+"POT-Creation-Date: 2014-07-02 13:00+0000\n"
102+"PO-Revision-Date: 2014-07-02 13:00+0000\n"
103+"Last-Translator: <>\n"
104+"Language-Team: \n"
105+"MIME-Version: 1.0\n"
106+"Content-Type: text/plain; charset=UTF-8\n"
107+"Content-Transfer-Encoding: \n"
108+"Plural-Forms: \n"
109+
110+#. module: purchase_budget_limit
111+#: view:purchase.budget.wizard:0
112+msgid "Block Purchase Order"
113+msgstr "Bloquer les commandes d'achat"
114+
115+#. module: purchase_budget_limit
116+#: field:purchase.budget.wizard,budget_line_ids:0
117+msgid "Budget Lines"
118+msgstr "Lignes budgétaires"
119+
120+#. module: purchase_budget_limit
121+#: code:addons/purchase_budget_limit/purchase.py:105
122+#: view:purchase.budget.wizard:0
123+#, python-format
124+msgid "Budget warning"
125+msgstr "Avertissement budgétaire"
126+
127+#. module: purchase_budget_limit
128+#: view:purchase.order:0
129+msgid "Cancel Order"
130+msgstr "Annuler la commande"
131+
132+#. module: purchase_budget_limit
133+#: view:purchase.budget.wizard:0
134+#: view:purchase.order:0
135+msgid "Override Budgets"
136+msgstr "Outrepasser les budgets"
137+
138+#. module: purchase_budget_limit
139+#: code:_description:0
140+#: model:ir.model,name:purchase_budget_limit.model_purchase_order
141+#, python-format
142+msgid "Purchase Order"
143+msgstr "Commande d'achat"
144+
145+#. module: purchase_budget_limit
146+#: view:purchase.budget.wizard:0
147+msgid "The following Budget Lines will be exhausted if you confirm the Purchase Order: you may have dificulties paying the Supplier Invoice."
148+msgstr "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."
149+
150+#. module: purchase_budget_limit
151+#: view:purchase.order:0
152+msgid "button_confirm"
153+msgstr "button_confirm"
154+
155+#. module: purchase_budget_limit
156+#: view:purchase.order:0
157+msgid "object"
158+msgstr "object"
159+
160+#. module: purchase_budget_limit
161+#: code:_description:0
162+#: model:ir.model,name:purchase_budget_limit.model_purchase_budget_wizard
163+#, python-format
164+msgid "purchase.budget.wizard"
165+msgstr "purchase.budget.wizard"
166+
167
168=== added file 'purchase_budget_limit/i18n/purchase_budget_limit.pot'
169--- purchase_budget_limit/i18n/purchase_budget_limit.pot 1970-01-01 00:00:00 +0000
170+++ purchase_budget_limit/i18n/purchase_budget_limit.pot 2014-07-02 13:10:24 +0000
171@@ -0,0 +1,74 @@
172+# Translation of OpenERP Server.
173+# This file contains the translation of the following modules:
174+# * purchase_budget_limit
175+#
176+msgid ""
177+msgstr ""
178+"Project-Id-Version: OpenERP Server 7.0\n"
179+"Report-Msgid-Bugs-To: \n"
180+"POT-Creation-Date: 2014-07-02 13:00+0000\n"
181+"PO-Revision-Date: 2014-07-02 13:00+0000\n"
182+"Last-Translator: <>\n"
183+"Language-Team: \n"
184+"MIME-Version: 1.0\n"
185+"Content-Type: text/plain; charset=UTF-8\n"
186+"Content-Transfer-Encoding: \n"
187+"Plural-Forms: \n"
188+
189+#. module: purchase_budget_limit
190+#: view:purchase.budget.wizard:0
191+msgid "Block Purchase Order"
192+msgstr ""
193+
194+#. module: purchase_budget_limit
195+#: field:purchase.budget.wizard,budget_line_ids:0
196+msgid "Budget Lines"
197+msgstr ""
198+
199+#. module: purchase_budget_limit
200+#: code:addons/purchase_budget_limit/purchase.py:105
201+#: view:purchase.budget.wizard:0
202+#, python-format
203+msgid "Budget warning"
204+msgstr ""
205+
206+#. module: purchase_budget_limit
207+#: view:purchase.order:0
208+msgid "Cancel Order"
209+msgstr ""
210+
211+#. module: purchase_budget_limit
212+#: view:purchase.budget.wizard:0
213+#: view:purchase.order:0
214+msgid "Override Budgets"
215+msgstr ""
216+
217+#. module: purchase_budget_limit
218+#: code:_description:0
219+#: model:ir.model,name:purchase_budget_limit.model_purchase_order
220+#, python-format
221+msgid "Purchase Order"
222+msgstr ""
223+
224+#. module: purchase_budget_limit
225+#: view:purchase.budget.wizard:0
226+msgid "The following Budget Lines will be exhausted if you confirm the Purchase Order: you may have dificulties paying the Supplier Invoice."
227+msgstr ""
228+
229+#. module: purchase_budget_limit
230+#: view:purchase.order:0
231+msgid "button_confirm"
232+msgstr ""
233+
234+#. module: purchase_budget_limit
235+#: view:purchase.order:0
236+msgid "object"
237+msgstr ""
238+
239+#. module: purchase_budget_limit
240+#: code:_description:0
241+#: model:ir.model,name:purchase_budget_limit.model_purchase_budget_wizard
242+#, python-format
243+msgid "purchase.budget.wizard"
244+msgstr ""
245+
246
247=== added file 'purchase_budget_limit/purchase.py'
248--- purchase_budget_limit/purchase.py 1970-01-01 00:00:00 +0000
249+++ purchase_budget_limit/purchase.py 2014-07-02 13:10:24 +0000
250@@ -0,0 +1,116 @@
251+# -*- coding: utf-8 -*-
252+##############################################################################
253+#
254+# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
255+#
256+# This program is free software: you can redistribute it and/or modify
257+# it under the terms of the GNU Affero General Public License as
258+# published by the Free Software Foundation, either version 3 of the
259+# License, or (at your option) any later version.
260+#
261+# This program is distributed in the hope that it will be useful,
262+# but WITHOUT ANY WARRANTY; without even the implied warranty of
263+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
264+# GNU Affero General Public License for more details.
265+#
266+# You should have received a copy of the GNU Affero General Public License
267+# along with this program. If not, see <http://www.gnu.org/licenses/>.
268+#
269+##############################################################################
270+
271+import time
272+
273+from openerp import netsvc
274+from openerp.osv import orm
275+from openerp.tools.translate import _
276+
277+
278+class PurchaseOrder (orm.Model):
279+ """Display a warning when confirming a Purchase if the budget is too low"""
280+ _inherit = 'purchase.order'
281+
282+ # Initialization (no context)
283+ def __init__(self, pool, cr):
284+ """
285+ Add a new state value.
286+
287+ Doing it in __init__ is cleaner than copying and pasting the field
288+ definition in _columns and should be compatible with future/customized
289+ versions.
290+ """
291+ super(PurchaseOrder, self).__init__(pool, cr)
292+ super(PurchaseOrder, self).STATE_SELECTION.append(
293+ ('over_budget', 'Over Budget'))
294+
295+ # Workflow Action methods (no context)
296+ def wkf_over_budget(self, cr, uid, ids):
297+ """Change the Purchase Order's state to 'Over Budget'"""
298+ self.write(cr, uid, ids, {'state': 'over_budget'})
299+ return True
300+
301+ # Model methods (context except when called by the Workflow Engine)
302+ def exhausted_budget_lines(self, cr, uid, ids, context=None):
303+ """
304+ Find the Budget Line which do not have enough funds left to pay the POs
305+
306+ @return: IDs of the Budget Lines
307+ """
308+ if not isinstance(ids, list):
309+ ids = [ids]
310+
311+ budget_line_ids = set()
312+ b_line_obj = self.pool['crossovered.budget.lines']
313+ today = time.strftime('%Y-%m-%d')
314+ for po_id in ids:
315+ for ol in self.browse(cr, uid, po_id, context=context).order_line:
316+ if ol.account_analytic_id:
317+ # should we check sub-accounts too?
318+ bl_ids = b_line_obj.search(
319+ cr, uid,
320+ [('analytic_account_id',
321+ '=', ol.account_analytic_id.id),
322+ ('date_from', '<=', today),
323+ ('date_to', '>=', today)],
324+ context=context)
325+ budget_line_ids.update(
326+ [l.id for l in b_line_obj.browse(
327+ cr, uid, bl_ids, context=context)
328+ if l.crossovered_budget_id.state == 'validate'
329+ and (l.practical_amount - ol.price_subtotal
330+ < l.theoritical_amount)])
331+ return list(budget_line_ids)
332+
333+ def button_confirm(self, cr, uid, ids, context=None):
334+ """Advance the workflow and pop up a message on 'Over Budget' state.
335+
336+ @return: True if all orders are OK, or an client action dictionary to
337+ open a confirmation wizard if any order is over-budget.
338+ """
339+ if context is None:
340+ context = {}
341+ if not isinstance(ids, list):
342+ ids = [ids]
343+
344+ # Send the workflow signal on every purchase order
345+ wf_service = netsvc.LocalService("workflow")
346+ for po_id in ids:
347+ wf_service.trg_validate(
348+ uid, self._name, po_id, 'purchase_confirm', cr)
349+
350+ # Return True or an Action dictionary
351+ orders_ok = all([o.state != 'over_budget'
352+ for o in self.browse(cr, uid, ids, context=context)])
353+
354+ return orders_ok or {
355+ 'name': _('Budget warning'),
356+ 'type': 'ir.actions.act_window',
357+ 'res_model': 'purchase.budget.wizard',
358+ 'view_type': 'form',
359+ 'view_mode': 'form',
360+ 'target': 'new',
361+ 'nodestroy': True,
362+ 'context': dict(context,
363+ active_model='purchase.order',
364+ active_ids=ids,
365+ active_id=ids[0])
366+ }
367
368=== added file 'purchase_budget_limit/purchase_view.xml'
369--- purchase_budget_limit/purchase_view.xml 1970-01-01 00:00:00 +0000
370+++ purchase_budget_limit/purchase_view.xml 2014-07-02 13:10:24 +0000
371@@ -0,0 +1,31 @@
372+<?xml version="1.0" encoding="utf-8"?>
373+<openerp>
374+ <data>
375+ <!-- Adapt the buttons in the form view to handle the new workflow and the state "Over Budget" -->
376+ <record id="purchase_order_form_over_budget" model="ir.ui.view">
377+ <field name="name">purchase.order.form.over_budget</field>
378+ <field name="inherit_id" ref="purchase.purchase_order_form" />
379+ <field name="model">purchase.order</field>
380+ <field name="arch" type="xml">
381+ <data>
382+ <!-- Tweak the button "Confirm" to start a wizard when Budget Lines are exhausted -->
383+ <xpath expr="//button[@name='purchase_confirm']" position="attributes">
384+ <attribute name="name">button_confirm</attribute>
385+ <attribute name="type">object</attribute>
386+ </xpath>
387+ <!-- Add a button to confirm over-budget POs
388+ Let users cancel over-budget POs -->
389+ <xpath expr="//button[@name='purchase_cancel']" position="after">
390+ <button name="purchase_cancel" states="over_budget" string="Cancel Order"/>
391+ <button name="purchase_confirm_overbudget" states="over_budget" string="Override Budgets" class="oe_highlight"/>
392+ </xpath>
393+ </data>
394+ </field>
395+ </record>
396+
397+ <!-- Add the state "Over Budget" to the "Draft" search filter and list -->
398+ <record id="purchase.purchase_rfq" model="ir.actions.act_window">
399+ <field name="domain">[('state','in',('draft','sent','confirmed','over_budget'))]</field>
400+ </record>
401+ </data>
402+</openerp>
403
404=== added file 'purchase_budget_limit/purchase_workflow.xml'
405--- purchase_budget_limit/purchase_workflow.xml 1970-01-01 00:00:00 +0000
406+++ purchase_budget_limit/purchase_workflow.xml 2014-07-02 13:10:24 +0000
407@@ -0,0 +1,34 @@
408+<?xml version="1.0" encoding="utf-8"?>
409+<openerp>
410+ <data>
411+ <!-- New activity for purchase orders when Budget Lines are exhausted -->
412+ <!-- Whenever a PO is Over-budget, the signal "purchase_confirm_overbudget" must be sent to override -->
413+ <record id="act_over_budget" model="workflow.activity">
414+ <field name="wkf_id" ref="purchase.purchase_order" />
415+ <field name="name">over_budget</field>
416+ <field name="kind">function</field>
417+ <field name="action">wkf_over_budget()</field>
418+ </record>
419+ <record id="trans_draft_over_budget" model="workflow.transition">
420+ <field name="act_from" ref="purchase.act_draft"/>
421+ <field name="act_to" ref="act_over_budget"/>
422+ <field name="signal">purchase_confirm</field>
423+ <field name="condition">exhausted_budget_lines()</field>
424+ </record>
425+ <record id="trans_over_budget_confirm" model="workflow.transition">
426+ <field name="act_from" ref="act_over_budget"/>
427+ <field name="act_to" ref="purchase.act_confirmed"/>
428+ <field name="signal">purchase_confirm_overbudget</field>
429+ </record>
430+ <record id="trans_over_budget_cancel" model="workflow.transition">
431+ <field name="act_from" ref="act_over_budget"/>
432+ <field name="act_to" ref="purchase.act_cancel"/>
433+ <field name="signal">purchase_cancel</field>
434+ </record>
435+
436+ <!-- only move from draft to confirm if budgets are OK -->
437+ <record id="purchase.trans_draft_confirmed" model="workflow.transition">
438+ <field name="condition">not exhausted_budget_lines()</field>
439+ </record>
440+ </data>
441+</openerp>
442
443=== added directory 'purchase_budget_limit/security'
444=== added file 'purchase_budget_limit/security/ir.model.access.csv'
445--- purchase_budget_limit/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
446+++ purchase_budget_limit/security/ir.model.access.csv 2014-07-02 13:10:24 +0000
447@@ -0,0 +1,3 @@
448+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
449+access_budget_purchase_user,Purchase users can read budgets,account_budget.model_crossovered_budget_lines,purchase.group_purchase_user,1,0,0,0
450+access_budget_purchase_user_manager,Purchase managers can read budgets,account_budget.model_crossovered_budget_lines,purchase.group_purchase_manager,1,0,0,0
451
452=== added directory 'purchase_budget_limit/wizard'
453=== added file 'purchase_budget_limit/wizard/__init__.py'
454--- purchase_budget_limit/wizard/__init__.py 1970-01-01 00:00:00 +0000
455+++ purchase_budget_limit/wizard/__init__.py 2014-07-02 13:10:24 +0000
456@@ -0,0 +1,21 @@
457+# -*- coding: utf-8 -*-
458+##############################################################################
459+#
460+# This module is copyright (C) 2011 Numérigraphe SARL. All Rights Reserved.
461+#
462+# This program is free software: you can redistribute it and/or modify
463+# it under the terms of the GNU General Public License as published by
464+# the Free Software Foundation, either version 3 of the License, or
465+# (at your option) any later version.
466+#
467+# This program is distributed in the hope that it will be useful,
468+# but WITHOUT ANY WARRANTY; without even the implied warranty of
469+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
470+# GNU General Public License for more details.
471+#
472+# You should have received a copy of the GNU General Public License
473+# along with this program. If not, see <http://www.gnu.org/licenses/>.
474+#
475+##############################################################################
476+
477+from . import purchase_budget
478
479=== added file 'purchase_budget_limit/wizard/purchase_budget.py'
480--- purchase_budget_limit/wizard/purchase_budget.py 1970-01-01 00:00:00 +0000
481+++ purchase_budget_limit/wizard/purchase_budget.py 2014-07-02 13:10:24 +0000
482@@ -0,0 +1,62 @@
483+# -*- coding: utf-8 -*-
484+##############################################################################
485+#
486+# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
487+#
488+# This program is free software: you can redistribute it and/or modify
489+# it under the terms of the GNU Affero General Public License as
490+# published by the Free Software Foundation, either version 3 of the
491+# License, or (at your option) any later version.
492+#
493+# This program is distributed in the hope that it will be useful,
494+# but WITHOUT ANY WARRANTY; without even the implied warranty of
495+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
496+# GNU Affero General Public License for more details.
497+#
498+# You should have received a copy of the GNU Affero General Public License
499+# along with this program. If not, see <http://www.gnu.org/licenses/>.
500+#
501+##############################################################################
502+
503+import openerp.netsvc as netsvc
504+from openerp.osv import fields, osv
505+
506+
507+class PurchaseBudget(osv.TransientModel):
508+ _name = 'purchase.budget.wizard'
509+ _columns = {
510+ 'budget_line_ids': fields.many2many("crossovered.budget.lines",
511+ rel='purchase_budget_lines_rel',
512+ id1='order_id', id2='line_id',
513+ string='Budget Lines',
514+ readonly=True),
515+ }
516+
517+ def _get_budget_line_ids(self, cr, uid, context=None):
518+ """Load the exhausted budget lines related to the Purchase Orders"""
519+ if context is None:
520+ context = {}
521+ if context.get('active_model') != 'purchase.order':
522+ return []
523+ return self.pool['purchase.order'].exhausted_budget_lines(
524+ cr, uid, context.get('active_ids'), context=context)
525+
526+ def override_budget(self, cr, uid, ids, context=None):
527+ """Override the Budgets and confirm the Purchase Order"""
528+ if context is None:
529+ context = {}
530+ if context.get('active_model') != 'purchase.order':
531+ return False
532+
533+ # Send the workflow signal on every purchase order
534+ wf_service = netsvc.LocalService("workflow")
535+ for po_id in context.get('active_ids'):
536+ wf_service.trg_validate(
537+ uid, 'purchase.order', po_id, 'purchase_confirm_overbudget',
538+ cr)
539+ return {'type': 'ir.actions.act_window_close'}
540+
541+ _defaults = {
542+ 'budget_line_ids': _get_budget_line_ids
543+ }
544+PurchaseBudget()
545
546=== added file 'purchase_budget_limit/wizard/purchase_budget_view.xml'
547--- purchase_budget_limit/wizard/purchase_budget_view.xml 1970-01-01 00:00:00 +0000
548+++ purchase_budget_limit/wizard/purchase_budget_view.xml 2014-07-02 13:10:24 +0000
549@@ -0,0 +1,20 @@
550+<?xml version="1.0" encoding="UTF-8"?>
551+<openerp>
552+ <data>
553+ <record id="purchase_budget_wizard_form" model="ir.ui.view">
554+ <field name="name">purchase.budget.wizard.form</field>
555+ <field name="model">purchase.budget.wizard</field>
556+ <field name="type">form</field>
557+ <field name="arch" type="xml">
558+ <form string="Budget warning" version="7.0">
559+ <label string="The following Budget Lines will be exhausted if you confirm the Purchase Order: you may have dificulties paying the Supplier Invoice."/>
560+ <field name="budget_line_ids" nolabel="1"/>
561+ <footer>
562+ <button special="cancel" string="Block Purchase Order" class="oe_highlight"/>
563+ <button name="override_budget" string="Override Budgets" type="object"/>
564+ </footer>
565+ </form>
566+ </field>
567+ </record>
568+ </data>
569+</openerp>

Subscribers

People subscribed via source and target branches