Merge lp:~roberto-v/account-payment/adding_account_vat_on_payment_7 into lp:~domsense/account-payment/adding_account_vat_on_payment_7

Proposed by Roberto Gianassi
Status: Merged
Merged at revision: 111
Proposed branch: lp:~roberto-v/account-payment/adding_account_vat_on_payment_7
Merge into: lp:~domsense/account-payment/adding_account_vat_on_payment_7
Diff against target: 141 lines (+102/-0)
5 files modified
account_vat_on_payment/__init__.py (+1/-0)
account_vat_on_payment/__openerp__.py (+1/-0)
account_vat_on_payment/account.py (+16/-0)
account_vat_on_payment/partner.py (+36/-0)
account_vat_on_payment/partner_view.xml (+48/-0)
To merge this branch: bzr merge lp:~roberto-v/account-payment/adding_account_vat_on_payment_7
Reviewer Review Type Date Requested Status
Lorenzo Battistini Approve
Review via email: mp+205723@code.launchpad.net
To post a comment you must log in.
112. By Roberto Gianassi

[IMP] Copyright fix.

Revision history for this message
Lorenzo Battistini (elbati) wrote :

Ciao Roberto,
many thanks for your contribution.

Some remarks:
 - Why is default_has_vat_on_payment a selection instead of a boolean?
 - Now, if the vat_on_payment invoice field is (correctly) set by the onchange_partner_id method, probably the _get_vat_on_payment method should be used to set the default value of default_has_vat_on_payment when creating new partners
 - Please run a PEP8 validator on your code

review: Needs Fixing
Revision history for this message
Roberto Gianassi (roberto-v) wrote :

> Ciao Roberto,

Ciao Lorenzo,

> many thanks for your contribution.
>
> Some remarks:
> - Why is default_has_vat_on_payment a selection instead of a boolean?

It is that way to force the user to always fill the right value.
If it were a boolean, it would be rendered on the UI as an initial empty checkbox: it would be very simple to forget to check the flag (when it has to be checked).

> - Now, if the vat_on_payment invoice field is (correctly) set by the
> onchange_partner_id method, probably the _get_vat_on_payment method should be
> used to set the default value of default_has_vat_on_payment when creating new
> partners

Please, could you elaborate a bit more on this?
What is the purpose of the _get_vat_on_payment method?

> - Please run a PEP8 validator on your code

Ok.

Thank you for the review.

113. By Roberto Gianassi

[IMP] PEP8 fixings.

114. By Roberto Gianassi

[FIX] Fixed a bug on XML record creation.

If a module (like fetchmail_invoice) containing a partner record to be
preinstalled through a data.xml file was installed after this one, a
bug occurred.
The bug shows because the record is created with the
default_has_vat_on_payment flag to empty and then validation fails.
To solve this, the create function for partners is changed to check for
the presence of that flag in the vals dictionary. If the flag is found,
we assume the creation happens through the UI and so normal checking goes
on. If the flag is not found, we assume the creation happens for an XML
record and so we add an arbitrary, but valid value for the flag.

115. By Roberto Gianassi

[FIX] Typo.

Revision history for this message
Lorenzo Battistini (elbati) wrote :

2014-02-11 18:03 GMT+01:00 Roberto Gianassi <email address hidden>:

> > Ciao Roberto,
>
> Ciao Lorenzo,
>
> > many thanks for your contribution.
> >
> > Some remarks:
> > - Why is default_has_vat_on_payment a selection instead of a boolean?
>
> It is that way to force the user to always fill the right value.
> If it were a boolean, it would be rendered on the UI as an initial empty
> checkbox: it would be very simple to forget to check the flag (when it has
> to be checked).
>

I mean, conceptually it is a boolean field, it can accept two values.
if I understand what you mean, you want to force the user to do a choice.
But this can be applied to every boolean field of OpenERP. So, in this
case, the boolean field interface behaviour should be changed system wide.

Moreover, using a boolean field allows you to avoid workaround like
this<http://bazaar.launchpad.net/~roberto-v/account-payment/adding_account_vat_on_payment_7/revision/114>

See below about setting a global default

>
> > - Now, if the vat_on_payment invoice field is (correctly) set by the
> > onchange_partner_id method, probably the _get_vat_on_payment method
> should be
> > used to set the default value of default_has_vat_on_payment when
> creating new
> > partners
>
> Please, could you elaborate a bit more on this?
> What is the purpose of the _get_vat_on_payment method?
>

At the moment, it sets the default value for 'vat_on_payment' field of
account.invoice, retrieving it from the global setting 'vat_on_payment'.
It think, after your changes, the global vat_on_payment setting should be
used for the default_has_vat_on_payment field.

Thanks

Revision history for this message
Roberto Gianassi (roberto-v) wrote :

> 2014-02-11 18:03 GMT+01:00 Roberto Gianassi <email address hidden>:
>
> > > Ciao Roberto,
> >
> > Ciao Lorenzo,
> >
> > > many thanks for your contribution.
> > >
> > > Some remarks:
> > > - Why is default_has_vat_on_payment a selection instead of a boolean?
> >
> > It is that way to force the user to always fill the right value.
> > If it were a boolean, it would be rendered on the UI as an initial empty
> > checkbox: it would be very simple to forget to check the flag (when it has
> > to be checked).
> >
>
> I mean, conceptually it is a boolean field, it can accept two values.
> if I understand what you mean, you want to force the user to do a choice.
> But this can be applied to every boolean field of OpenERP. So, in this
> case, the boolean field interface behaviour should be changed system wide.
>
> Moreover, using a boolean field allows you to avoid workaround like
> this<http://bazaar.launchpad.net/~roberto-v/account-
> payment/adding_account_vat_on_payment_7/revision/114>
>
> See below about setting a global default
>

Yes, I see your point.
The problem is that the vat_on_payment flag has to be set differently for every supplier.
There are some rules (for example the supplier has to be Italian) on when you can use VAT on Payment or not and an error here may have legal/financial consequences.
Technically, the selection will be equivalent to a required field. I know you can make a Boolean required, but, in practice, it has no effect (the user can simply ignore it).
I don't know if there are other ways to force a user to make a Boolean choice. In case, let me know.
I need the patch this way. If this is not possible I will go with a custom module.

Thanks for your time.

116. By Roberto Gianassi

[ADD] Moved default_has_vat_on_payment on account.fiscal.position.

After some research, the VAT on Payment seems dependent on the account
fiscal position of the customer/supplier.
Moved the default_has_vat_on_payment flag to that model to take that
into account.
The field is now a boolean because is not needed anymore to force the
user to make a choice.

117. By Roberto Gianassi

[FIX] When partner field is empty value is False.

The value passed to the onchange_partner_id for the partner is False
when the field is empty. In this case, it is not possible to use such a
value with the browse function or an error arises. Fixed that.

Revision history for this message
Lorenzo Battistini (elbati) wrote :

Roberto, thanks for your changes.
I think using fiscal positions is a better choice.

Some remarks:
line 39: 'for partner_id in partner_obj.browse(cr, uid, [partner_id])' can just be 'partner = partner_obj.browse(cr, uid, partner_id, context=context)'
line 41: if 'property_account_position' was not set, partner.property_account_position.default_has_vat_on_payment would raise exception
line 89, I think the _defaults is unnecessary

review: Needs Fixing
118. By Roberto Gianassi

[FIX] Fixing remarks.

Revision history for this message
Lorenzo Battistini (elbati) wrote :

Thanks.

PS: please send a message after the changes, launchpad does not automatically notifies of new commits

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

This project is now hosted on https://github.com/OCA/account-payment. 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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_vat_on_payment/__init__.py'
--- account_vat_on_payment/__init__.py 2013-05-15 09:35:50 +0000
+++ account_vat_on_payment/__init__.py 2014-02-24 09:06:14 +0000
@@ -22,3 +22,4 @@
22##############################################################################22##############################################################################
23import account23import account
24import company24import company
25import partner
2526
=== modified file 'account_vat_on_payment/__openerp__.py'
--- account_vat_on_payment/__openerp__.py 2013-11-27 14:37:50 +0000
+++ account_vat_on_payment/__openerp__.py 2014-02-24 09:06:14 +0000
@@ -52,6 +52,7 @@
52 'update_xml': [52 'update_xml': [
53 'account_view.xml',53 'account_view.xml',
54 'company_view.xml',54 'company_view.xml',
55 'partner_view.xml',
55 ],56 ],
56 'demo_xml': [], # TODO YAML tests57 'demo_xml': [], # TODO YAML tests
57 'installable': True,58 'installable': True,
5859
=== modified file 'account_vat_on_payment/account.py'
--- account_vat_on_payment/account.py 2013-11-28 07:11:33 +0000
+++ account_vat_on_payment/account.py 2014-02-24 09:06:14 +0000
@@ -336,6 +336,22 @@
336 new_move_lines.append(line_tup)336 new_move_lines.append(line_tup)
337 return new_move_lines337 return new_move_lines
338338
339 def onchange_partner_id(
340 self, cr, uid, ids, type, partner_id, date_invoice=False,
341 payment_term=False, partner_bank_id=False, company_id=False):
342 res = super(account_invoice, self).onchange_partner_id(
343 cr, uid, ids, type, partner_id, date_invoice, payment_term,
344 partner_bank_id, company_id)
345 # default value for VAT on Payment is changed every time the
346 # customer/supplier is changed
347 partner_obj = self.pool.get("res.partner")
348 if partner_id:
349 p = partner_obj.browse(cr, uid, partner_id)
350 res['value']['vat_on_payment'] = p.property_account_position\
351 and p.property_account_position.default_has_vat_on_payment\
352 or False
353 return res
354
339 _inherit = "account.invoice"355 _inherit = "account.invoice"
340 _columns = {356 _columns = {
341 'vat_on_payment': fields.boolean('Vat on payment'),357 'vat_on_payment': fields.boolean('Vat on payment'),
342358
=== added file 'account_vat_on_payment/partner.py'
--- account_vat_on_payment/partner.py 1970-01-01 00:00:00 +0000
+++ account_vat_on_payment/partner.py 2014-02-24 09:06:14 +0000
@@ -0,0 +1,36 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2011-2012 Domsense s.r.l. (<http://www.domsense.com>).
6# Copyright (C) 2012-2013 Agile Business Group sagl
7# (<http://www.agilebg.com>)
8# Copyright (C) 2014 Develer srl (<http://www.develer.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
25
26from openerp.osv import fields, orm
27from openerp.tools.translate import _
28
29
30class account_fiscal_position(orm.Model):
31 _inherit = 'account.fiscal.position'
32
33 _columns = {
34 'default_has_vat_on_payment': fields.boolean(
35 'VAT on Payment Default Flag'),
36 }
037
=== added file 'account_vat_on_payment/partner_view.xml'
--- account_vat_on_payment/partner_view.xml 1970-01-01 00:00:00 +0000
+++ account_vat_on_payment/partner_view.xml 2014-02-24 09:06:14 +0000
@@ -0,0 +1,48 @@
1<?xml version="1.0"?>
2
3<!--
4# -*- coding: utf-8 -*-
5##############################################################################
6#
7# OpenERP, Open Source Management Solution
8# Copyright (C) 2011-2012 Domsense s.r.l. (<http://www.domsense.com>).
9# Copyright (C) 2012-2013 Agile Business Group sagl
10# (<http://www.agilebg.com>)
11# Copyright (C) 2014 Develer srl (<http://www.develer.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
29
30<openerp>
31 <data>
32
33 <!-- res.partner customizations -->
34
35 <record id="view_partner_form" model="ir.ui.view">
36 <field name="name">account.fiscal.position.vat.default.view</field>
37 <field name="model">account.fiscal.position</field>
38 <field name="inherit_id" ref="account.view_account_position_form"/>
39 <field name="arch" type="xml">
40 <field name="active" position="after" version="7.0">
41 <field name="default_has_vat_on_payment" class="oe_inline"/>
42 </field>
43 </field>
44 </record>
45
46
47 </data>
48</openerp>

Subscribers

People subscribed via source and target branches