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
=== added directory 'purchase_fiscal_position_update'
=== added file 'purchase_fiscal_position_update/__init__.py'
--- purchase_fiscal_position_update/__init__.py 1970-01-01 00:00:00 +0000
+++ purchase_fiscal_position_update/__init__.py 2014-01-09 22:36:59 +0000
@@ -0,0 +1,23 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Purchase Fiscal Position Update module for OpenERP
5# Copyright (C) 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
6# Copyright (C) 2014 Akretion (http://www.akretion.com)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import purchase
024
=== added file 'purchase_fiscal_position_update/__openerp__.py'
--- purchase_fiscal_position_update/__openerp__.py 1970-01-01 00:00:00 +0000
+++ purchase_fiscal_position_update/__openerp__.py 2014-01-09 22:36:59 +0000
@@ -0,0 +1,40 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Purchase Fiscal Position Update module for OpenERP
5# Copyright (C) 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
6# Copyright (C) 2014 Akretion (http://www.akretion.com)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23{
24 'name': 'Purchase Fiscal Position Update',
25 'version': '1.0',
26 'category': 'Purchase Management',
27 'license': 'AGPL-3',
28 'summary': 'Changing the fiscal position of a purchase order will auto-update purchase order lines',
29 'description': """
30Purchase Fiscal Position Update
31===============================
32
33With 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.
34""",
35 'author': 'Julius Network Solutions, Akretion',
36 'depends': ['purchase'],
37 'data': ['purchase_view.xml'],
38 'installable': True,
39 'active': False,
40}
041
=== added directory 'purchase_fiscal_position_update/i18n'
=== added file 'purchase_fiscal_position_update/i18n/fr.po'
--- purchase_fiscal_position_update/i18n/fr.po 1970-01-01 00:00:00 +0000
+++ purchase_fiscal_position_update/i18n/fr.po 2014-01-09 22:36:59 +0000
@@ -0,0 +1,51 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * purchase_fiscal_position_update
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-01-09 22:16+0000\n"
10"PO-Revision-Date: 2014-01-09 22:16+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_fiscal_position_update
19#: code:addons/purchase_fiscal_position_update/purchase.py:70
20#, python-format
21msgid "The Purchase Order Lines were not updated to the new Fiscal Position because they don't have Products.\n"
22"You should update the Taxes of each Purchase Order Line manually."
23msgstr "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"
24"Vous devez mettre à jour manuellement les taxes sur chaque ligne de commande."
25
26#. module: purchase_fiscal_position_update
27#: code:addons/purchase_fiscal_position_update/purchase.py:79
28#, python-format
29msgid "The following Purchase Order Lines were not updated to the new Fiscal Position because they don't have a Product:\n"
30" %s\n"
31"You should update the Taxes of these Purchase Order Lines manually."
32msgstr "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"
33" %s\n"
34"Vous devez mettre à jour manuellement les taxes sur ces lignes de commande."
35
36#. module: purchase_fiscal_position_update
37#: view:purchase.order:0
38msgid "fiscal_position_change(fiscal_position, order_line, context)"
39msgstr "fiscal_position_change(fiscal_position, order_line, context)"
40
41#. module: purchase_fiscal_position_update
42#: code:addons/purchase_fiscal_position_update/purchase.py:68
43#, python-format
44msgid "Warning"
45msgstr "Avertissement"
46
47#. module: purchase_fiscal_position_update
48#: model:ir.model,name:purchase_fiscal_position_update.model_purchase_order
49msgid "Purchase Order"
50msgstr "Bon de commande"
51
052
=== added file 'purchase_fiscal_position_update/i18n/purchase_fiscal_position_update.pot'
--- purchase_fiscal_position_update/i18n/purchase_fiscal_position_update.pot 1970-01-01 00:00:00 +0000
+++ purchase_fiscal_position_update/i18n/purchase_fiscal_position_update.pot 2014-01-09 22:36:59 +0000
@@ -0,0 +1,48 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * purchase_fiscal_position_update
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-01-09 22:15+0000\n"
10"PO-Revision-Date: 2014-01-09 22:15+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_fiscal_position_update
19#: code:addons/purchase_fiscal_position_update/purchase.py:70
20#, python-format
21msgid "The Purchase Order Lines were not updated to the new Fiscal Position because they don't have Products.\n"
22"You should update the Taxes of each Purchase Order Line manually."
23msgstr ""
24
25#. module: purchase_fiscal_position_update
26#: code:addons/purchase_fiscal_position_update/purchase.py:79
27#, python-format
28msgid "The following Purchase Order Lines were not updated to the new Fiscal Position because they don't have a Product:\n"
29" %s\n"
30"You should update the Taxes of these Purchase Order Lines manually."
31msgstr ""
32
33#. module: purchase_fiscal_position_update
34#: view:purchase.order:0
35msgid "fiscal_position_change(fiscal_position, order_line, context)"
36msgstr ""
37
38#. module: purchase_fiscal_position_update
39#: code:addons/purchase_fiscal_position_update/purchase.py:68
40#, python-format
41msgid "Warning"
42msgstr ""
43
44#. module: purchase_fiscal_position_update
45#: model:ir.model,name:purchase_fiscal_position_update.model_purchase_order
46msgid "Purchase Order"
47msgstr ""
48
049
=== added file 'purchase_fiscal_position_update/purchase.py'
--- purchase_fiscal_position_update/purchase.py 1970-01-01 00:00:00 +0000
+++ purchase_fiscal_position_update/purchase.py 2014-01-09 22:36:59 +0000
@@ -0,0 +1,84 @@
1# -*- coding: utf-8 -*-
2#############################################################################
3#
4# Purchase Fiscal Position Update module for OpenERP
5# Copyright (C) 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
6# Copyright (C) 2014 Akretion (http://www.akretion.com)
7# @author Mathieu Vatel <mathieu _at_ julius.fr>
8# @author Alexis de Lattre <alexis.delattre@akretion.com>
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU Affero General Public License as
12# published by the Free Software Foundation, either version 3 of the
13# License, or (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU Affero General Public License for more details.
19#
20# You should have received a copy of the GNU Affero General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
23##############################################################################
24
25from openerp.osv import orm
26from openerp.tools.translate import _
27
28
29class purchase_order(orm.Model):
30 _inherit = "purchase.order"
31
32 def fiscal_position_change(
33 self, cr, uid, ids, fiscal_position, order_line,
34 context=None):
35 '''Function executed by the on_change on the fiscal_position field
36 of a purchase order ; it updates taxes on all order lines'''
37 assert len(ids) in (0, 1), 'One ID max'
38 fp_obj = self.pool['account.fiscal.position']
39 res = {}
40 line_dict = self.resolve_2many_commands(
41 cr, uid, 'order_line', order_line, context=context)
42 lines_without_product = []
43 if fiscal_position:
44 fp = fp_obj.browse(cr, uid, fiscal_position, context=context)
45 else:
46 fp = False
47 for line in line_dict:
48 # Reformat line_dict so as to be compatible with what is
49 # accepted in res['value']
50 for key, value in line.iteritems():
51 if isinstance(value, tuple) and len(value) == 2:
52 line[key] = value[0]
53 if line.get('product_id'):
54 product = self.pool['product.product'].browse(
55 cr, uid, line.get('product_id'), context=context)
56 taxes = product.supplier_taxes_id
57 tax_ids = fp_obj.map_tax(
58 cr, uid, fp, taxes, context=context)
59
60 line['taxes_id'] = [(6, 0, tax_ids)]
61 else:
62 lines_without_product.append(line.get('name'))
63 res['value'] = {}
64 res['value']['order_line'] = line_dict
65
66 if lines_without_product:
67 res['warning'] = {'title': _('Warning')}
68 if len(lines_without_product) == len(line_dict):
69 res['warning']['message'] = _(
70 "The Purchase Order Lines were not updated to the new "
71 "Fiscal Position because they don't have Products.\n"
72 "You should update the Taxes of each "
73 "Purchase Order Line manually.")
74 else:
75 display_line_names = ''
76 for name in lines_without_product:
77 display_line_names += "- %s\n" % name
78 res['warning']['message'] = _(
79 "The following Purchase Order Lines were not updated "
80 "to the new Fiscal Position because they don't have a "
81 "Product:\n %s\nYou should update the "
82 "Taxes of these Purchase Order Lines manually."
83 ) % display_line_names,
84 return res
085
=== added file 'purchase_fiscal_position_update/purchase_view.xml'
--- purchase_fiscal_position_update/purchase_view.xml 1970-01-01 00:00:00 +0000
+++ purchase_fiscal_position_update/purchase_view.xml 2014-01-09 22:36:59 +0000
@@ -0,0 +1,23 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3<data>
4
5<!--
6 Copyright (C) 2014 Akretion (http://www.akretion.com/)
7 @author Alexis de Lattre <alexis.delattre@akretion.com>
8 The licence is in the file __openerp__.py
9-->
10
11<record id="purchase_order_form" model="ir.ui.view">
12 <field name="name">fiscal.position.update.purchase.order.form</field>
13 <field name="model">purchase.order</field>
14 <field name="inherit_id" ref="purchase.purchase_order_form"/>
15 <field name="arch" type="xml">
16 <field name="fiscal_position" position="attributes">
17 <attribute name="on_change">fiscal_position_change(fiscal_position, order_line, context)</attribute>
18 </field>
19 </field>
20</record>
21
22</data>
23</openerp>

Subscribers

People subscribed via source and target branches