Merge lp:~akretion-team/purchase-wkfl/70-add-purchase_fiscal_position_update into lp:~purchase-core-editors/purchase-wkfl/7.0

Proposed by Alexis de Lattre
Status: Merged
Merged at revision: 23
Proposed branch: lp:~akretion-team/purchase-wkfl/70-add-purchase_fiscal_position_update
Merge into: lp:~purchase-core-editors/purchase-wkfl/7.0
Diff against target: 300 lines (+269/-0)
6 files modified
purchase_fiscal_position_update/__init__.py (+23/-0)
purchase_fiscal_position_update/__openerp__.py (+40/-0)
purchase_fiscal_position_update/i18n/fr.po (+51/-0)
purchase_fiscal_position_update/i18n/purchase_fiscal_position_update.pot (+48/-0)
purchase_fiscal_position_update/purchase.py (+84/-0)
purchase_fiscal_position_update/purchase_view.xml (+23/-0)
To merge this branch: bzr merge lp:~akretion-team/purchase-wkfl/70-add-purchase_fiscal_position_update
Reviewer Review Type Date Requested Status
Ronald Portier (Therp) (community) test Approve
Pedro Manuel Baeza code review Approve
Review via email: mp+201115@code.launchpad.net

Description of the change

Add purchase_fiscal_position_update module. Extract from the description :

With this module, when a user changes the fiscal position of a purchase order, the taxes on all the purchase order lines which have a product are automatically updated. The purchase order lines without a product are not updated and a warning is displayed to the user in this case.

The module is the equivalent of :
- the module invoice_fiscal_position_update, which is under review here : https://code.launchpad.net/~akretion-team/account-invoicing/70-add-invoice_fiscal_position_update/+merge/200358
- the module sale_fiscal_position_update, which is under review here : https://code.launchpad.net/~akretion-team/sale-wkfl/70-add-sale_fiscal_position_update/+merge/200611

So, with this MP, the family of fiscal_position_update is complete : sale + purchase + invoice !

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Very good! Thanks for your work!

Regards.

review: Approve (code review)
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Hello Alexis.

Thanks for this work.

Would it make sense to you to use the default tax from account (account.account.tax_id) if there is no tax defined on the product, like it is done in invoice and hr_expenses?

See also lp:796570

Revision history for this message
Alexis de Lattre (alexis-via) wrote :

@Stéphane

Thanks for pointing me to this interesting bug report.

I think that this module must be in sync with the state of the on_change of product_id in the purchase module in OCB-addons. For the moment, the on_change of product_id in OCB-addons doesn't take into account the default taxes if there are not taxes on the product. As soon as it changes, I will adapt my code to the new behavior. But I think it would be a mistake to change the code BEFORE the on_change of product_id is modified in the purchase module, because it would confuse users to have a different behavior when they add a new line in a PO vs when they update the fiscal position of the PO.

Revision history for this message
Ronald Portier (Therp) (rportier1962) wrote :

tested the module and it works as expected.

review: Approve (test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'purchase_fiscal_position_update'
2=== added file 'purchase_fiscal_position_update/__init__.py'
3--- purchase_fiscal_position_update/__init__.py 1970-01-01 00:00:00 +0000
4+++ purchase_fiscal_position_update/__init__.py 2014-01-09 22:36:59 +0000
5@@ -0,0 +1,23 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Purchase Fiscal Position Update module for OpenERP
10+# Copyright (C) 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
11+# Copyright (C) 2014 Akretion (http://www.akretion.com)
12+#
13+# This program is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU Affero General Public License as
15+# published by the Free Software Foundation, either version 3 of the
16+# License, or (at your option) any later version.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU Affero General Public License for more details.
22+#
23+# You should have received a copy of the GNU Affero General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25+#
26+##############################################################################
27+
28+from . import purchase
29
30=== added file 'purchase_fiscal_position_update/__openerp__.py'
31--- purchase_fiscal_position_update/__openerp__.py 1970-01-01 00:00:00 +0000
32+++ purchase_fiscal_position_update/__openerp__.py 2014-01-09 22:36:59 +0000
33@@ -0,0 +1,40 @@
34+# -*- coding: utf-8 -*-
35+##############################################################################
36+#
37+# Purchase Fiscal Position Update module for OpenERP
38+# Copyright (C) 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
39+# Copyright (C) 2014 Akretion (http://www.akretion.com)
40+#
41+# This program is free software: you can redistribute it and/or modify
42+# it under the terms of the GNU Affero General Public License as
43+# published by the Free Software Foundation, either version 3 of the
44+# License, or (at your option) any later version.
45+#
46+# This program is distributed in the hope that it will be useful,
47+# but WITHOUT ANY WARRANTY; without even the implied warranty of
48+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49+# GNU Affero General Public License for more details.
50+#
51+# You should have received a copy of the GNU Affero General Public License
52+# along with this program. If not, see <http://www.gnu.org/licenses/>.
53+#
54+##############################################################################
55+
56+{
57+ 'name': 'Purchase Fiscal Position Update',
58+ 'version': '1.0',
59+ 'category': 'Purchase Management',
60+ 'license': 'AGPL-3',
61+ 'summary': 'Changing the fiscal position of a purchase order will auto-update purchase order lines',
62+ 'description': """
63+Purchase Fiscal Position Update
64+===============================
65+
66+With this module, when a user changes the fiscal position of a purchase order, the taxes on all the purchase order lines which have a product are automatically updated. The purchase order lines without a product are not updated and a warning is displayed to the user in this case.
67+""",
68+ 'author': 'Julius Network Solutions, Akretion',
69+ 'depends': ['purchase'],
70+ 'data': ['purchase_view.xml'],
71+ 'installable': True,
72+ 'active': False,
73+}
74
75=== added directory 'purchase_fiscal_position_update/i18n'
76=== added file 'purchase_fiscal_position_update/i18n/fr.po'
77--- purchase_fiscal_position_update/i18n/fr.po 1970-01-01 00:00:00 +0000
78+++ purchase_fiscal_position_update/i18n/fr.po 2014-01-09 22:36:59 +0000
79@@ -0,0 +1,51 @@
80+# Translation of OpenERP Server.
81+# This file contains the translation of the following modules:
82+# * purchase_fiscal_position_update
83+#
84+msgid ""
85+msgstr ""
86+"Project-Id-Version: OpenERP Server 7.0\n"
87+"Report-Msgid-Bugs-To: \n"
88+"POT-Creation-Date: 2014-01-09 22:16+0000\n"
89+"PO-Revision-Date: 2014-01-09 22:16+0000\n"
90+"Last-Translator: <>\n"
91+"Language-Team: \n"
92+"MIME-Version: 1.0\n"
93+"Content-Type: text/plain; charset=UTF-8\n"
94+"Content-Transfer-Encoding: \n"
95+"Plural-Forms: \n"
96+
97+#. module: purchase_fiscal_position_update
98+#: code:addons/purchase_fiscal_position_update/purchase.py:70
99+#, python-format
100+msgid "The Purchase Order Lines were not updated to the new Fiscal Position because they don't have Products.\n"
101+"You should update the Taxes of each Purchase Order Line manually."
102+msgstr "Les lignes de commande n'ont pas été mise-à-jour suite au changement de la position fiscale car elle ne contiennent pas de produit.\n"
103+"Vous devez mettre à jour manuellement les taxes sur chaque ligne de commande."
104+
105+#. module: purchase_fiscal_position_update
106+#: code:addons/purchase_fiscal_position_update/purchase.py:79
107+#, python-format
108+msgid "The following Purchase Order Lines were not updated to the new Fiscal Position because they don't have a Product:\n"
109+" %s\n"
110+"You should update the Taxes of these Purchase Order Lines manually."
111+msgstr "Les lignes de commande suivantes n'ont pas été mise-à-jour suite au changement de la position fiscale car elle ne contiennent pas de produit :\n"
112+" %s\n"
113+"Vous devez mettre à jour manuellement les taxes sur ces lignes de commande."
114+
115+#. module: purchase_fiscal_position_update
116+#: view:purchase.order:0
117+msgid "fiscal_position_change(fiscal_position, order_line, context)"
118+msgstr "fiscal_position_change(fiscal_position, order_line, context)"
119+
120+#. module: purchase_fiscal_position_update
121+#: code:addons/purchase_fiscal_position_update/purchase.py:68
122+#, python-format
123+msgid "Warning"
124+msgstr "Avertissement"
125+
126+#. module: purchase_fiscal_position_update
127+#: model:ir.model,name:purchase_fiscal_position_update.model_purchase_order
128+msgid "Purchase Order"
129+msgstr "Bon de commande"
130+
131
132=== added file 'purchase_fiscal_position_update/i18n/purchase_fiscal_position_update.pot'
133--- purchase_fiscal_position_update/i18n/purchase_fiscal_position_update.pot 1970-01-01 00:00:00 +0000
134+++ purchase_fiscal_position_update/i18n/purchase_fiscal_position_update.pot 2014-01-09 22:36:59 +0000
135@@ -0,0 +1,48 @@
136+# Translation of OpenERP Server.
137+# This file contains the translation of the following modules:
138+# * purchase_fiscal_position_update
139+#
140+msgid ""
141+msgstr ""
142+"Project-Id-Version: OpenERP Server 7.0\n"
143+"Report-Msgid-Bugs-To: \n"
144+"POT-Creation-Date: 2014-01-09 22:15+0000\n"
145+"PO-Revision-Date: 2014-01-09 22:15+0000\n"
146+"Last-Translator: <>\n"
147+"Language-Team: \n"
148+"MIME-Version: 1.0\n"
149+"Content-Type: text/plain; charset=UTF-8\n"
150+"Content-Transfer-Encoding: \n"
151+"Plural-Forms: \n"
152+
153+#. module: purchase_fiscal_position_update
154+#: code:addons/purchase_fiscal_position_update/purchase.py:70
155+#, python-format
156+msgid "The Purchase Order Lines were not updated to the new Fiscal Position because they don't have Products.\n"
157+"You should update the Taxes of each Purchase Order Line manually."
158+msgstr ""
159+
160+#. module: purchase_fiscal_position_update
161+#: code:addons/purchase_fiscal_position_update/purchase.py:79
162+#, python-format
163+msgid "The following Purchase Order Lines were not updated to the new Fiscal Position because they don't have a Product:\n"
164+" %s\n"
165+"You should update the Taxes of these Purchase Order Lines manually."
166+msgstr ""
167+
168+#. module: purchase_fiscal_position_update
169+#: view:purchase.order:0
170+msgid "fiscal_position_change(fiscal_position, order_line, context)"
171+msgstr ""
172+
173+#. module: purchase_fiscal_position_update
174+#: code:addons/purchase_fiscal_position_update/purchase.py:68
175+#, python-format
176+msgid "Warning"
177+msgstr ""
178+
179+#. module: purchase_fiscal_position_update
180+#: model:ir.model,name:purchase_fiscal_position_update.model_purchase_order
181+msgid "Purchase Order"
182+msgstr ""
183+
184
185=== added file 'purchase_fiscal_position_update/purchase.py'
186--- purchase_fiscal_position_update/purchase.py 1970-01-01 00:00:00 +0000
187+++ purchase_fiscal_position_update/purchase.py 2014-01-09 22:36:59 +0000
188@@ -0,0 +1,84 @@
189+# -*- coding: utf-8 -*-
190+#############################################################################
191+#
192+# Purchase Fiscal Position Update module for OpenERP
193+# Copyright (C) 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
194+# Copyright (C) 2014 Akretion (http://www.akretion.com)
195+# @author Mathieu Vatel <mathieu _at_ julius.fr>
196+# @author Alexis de Lattre <alexis.delattre@akretion.com>
197+#
198+# This program is free software: you can redistribute it and/or modify
199+# it under the terms of the GNU Affero General Public License as
200+# published by the Free Software Foundation, either version 3 of the
201+# License, or (at your option) any later version.
202+#
203+# This program is distributed in the hope that it will be useful,
204+# but WITHOUT ANY WARRANTY; without even the implied warranty of
205+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
206+# GNU Affero General Public License for more details.
207+#
208+# You should have received a copy of the GNU Affero General Public License
209+# along with this program. If not, see <http://www.gnu.org/licenses/>.
210+#
211+##############################################################################
212+
213+from openerp.osv import orm
214+from openerp.tools.translate import _
215+
216+
217+class purchase_order(orm.Model):
218+ _inherit = "purchase.order"
219+
220+ def fiscal_position_change(
221+ self, cr, uid, ids, fiscal_position, order_line,
222+ context=None):
223+ '''Function executed by the on_change on the fiscal_position field
224+ of a purchase order ; it updates taxes on all order lines'''
225+ assert len(ids) in (0, 1), 'One ID max'
226+ fp_obj = self.pool['account.fiscal.position']
227+ res = {}
228+ line_dict = self.resolve_2many_commands(
229+ cr, uid, 'order_line', order_line, context=context)
230+ lines_without_product = []
231+ if fiscal_position:
232+ fp = fp_obj.browse(cr, uid, fiscal_position, context=context)
233+ else:
234+ fp = False
235+ for line in line_dict:
236+ # Reformat line_dict so as to be compatible with what is
237+ # accepted in res['value']
238+ for key, value in line.iteritems():
239+ if isinstance(value, tuple) and len(value) == 2:
240+ line[key] = value[0]
241+ if line.get('product_id'):
242+ product = self.pool['product.product'].browse(
243+ cr, uid, line.get('product_id'), context=context)
244+ taxes = product.supplier_taxes_id
245+ tax_ids = fp_obj.map_tax(
246+ cr, uid, fp, taxes, context=context)
247+
248+ line['taxes_id'] = [(6, 0, tax_ids)]
249+ else:
250+ lines_without_product.append(line.get('name'))
251+ res['value'] = {}
252+ res['value']['order_line'] = line_dict
253+
254+ if lines_without_product:
255+ res['warning'] = {'title': _('Warning')}
256+ if len(lines_without_product) == len(line_dict):
257+ res['warning']['message'] = _(
258+ "The Purchase Order Lines were not updated to the new "
259+ "Fiscal Position because they don't have Products.\n"
260+ "You should update the Taxes of each "
261+ "Purchase Order Line manually.")
262+ else:
263+ display_line_names = ''
264+ for name in lines_without_product:
265+ display_line_names += "- %s\n" % name
266+ res['warning']['message'] = _(
267+ "The following Purchase Order Lines were not updated "
268+ "to the new Fiscal Position because they don't have a "
269+ "Product:\n %s\nYou should update the "
270+ "Taxes of these Purchase Order Lines manually."
271+ ) % display_line_names,
272+ return res
273
274=== added file 'purchase_fiscal_position_update/purchase_view.xml'
275--- purchase_fiscal_position_update/purchase_view.xml 1970-01-01 00:00:00 +0000
276+++ purchase_fiscal_position_update/purchase_view.xml 2014-01-09 22:36:59 +0000
277@@ -0,0 +1,23 @@
278+<?xml version="1.0" encoding="utf-8"?>
279+<openerp>
280+<data>
281+
282+<!--
283+ Copyright (C) 2014 Akretion (http://www.akretion.com/)
284+ @author Alexis de Lattre <alexis.delattre@akretion.com>
285+ The licence is in the file __openerp__.py
286+-->
287+
288+<record id="purchase_order_form" model="ir.ui.view">
289+ <field name="name">fiscal.position.update.purchase.order.form</field>
290+ <field name="model">purchase.order</field>
291+ <field name="inherit_id" ref="purchase.purchase_order_form"/>
292+ <field name="arch" type="xml">
293+ <field name="fiscal_position" position="attributes">
294+ <attribute name="on_change">fiscal_position_change(fiscal_position, order_line, context)</attribute>
295+ </field>
296+ </field>
297+</record>
298+
299+</data>
300+</openerp>

Subscribers

People subscribed via source and target branches