Merge lp:~therp-nl/account-invoicing/7.0-add_account_invoice_partner into lp:~account-core-editors/account-invoicing/7.0

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Approved by: Guewen Baconnier @ Camptocamp
Approved revision: 23
Merged at revision: 34
Proposed branch: lp:~therp-nl/account-invoicing/7.0-add_account_invoice_partner
Merge into: lp:~account-core-editors/account-invoicing/7.0
Diff against target: 99 lines (+78/-0)
4 files modified
account_invoice_partner/__init__.py (+1/-0)
account_invoice_partner/__openerp__.py (+32/-0)
account_invoice_partner/model/__init__.py (+1/-0)
account_invoice_partner/model/account_invoice.py (+44/-0)
To merge this branch: bzr merge lp:~therp-nl/account-invoicing/7.0-add_account_invoice_partner
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Pedro Manuel Baeza code review and test Approve
Review via email: mp+180694@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Would it not be better to try to submit it as a (usability) bug first, and if accepted as such, patch it on the OCB branch?

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Stéphane,

I wondered about that. Reported here: https://bugs.launchpad.net/openobject-addons/+bug/1213852. I'll set this to work in progress till there is a response. Meanwhile, I refactored to use the same mechanisme as is used to select the invoicing contact in the Sale module.

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

Hi, Stefan,

I have seen your contribution and I see this module IMHO a little dangerous, because with it you are avoiding selecting any other contact that it isn't the invoice contact (or even the company). I think that the desirable behaviour must be that you can select any contact, but the invoice contact appear highlighted in first place and with some text to identify it. This can be extended also to the other types of contacts. For example:

- Contact 1, Company A [invoice]
- Company A
- Contact 2, Company A [delivery]
- Contact 3, Company A [other]

What do you think?

Regards.

review: Needs Information
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Pedro,

your observation is correct. That would be an argument to keep this functionality in an optional module instead of the core. I like the idea of annotating contacts with their contact type, but the use case here is simply that if an invoice contact is defined, then that contact should be used whenever an invoice is sent.

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

OK about that, Stefan.

I only see one problem in the module: you may insert one condition to check if the selected partner is already an invoice contact, because you can have more than one invoice contact, and in this way you are virtually forbidding to select second and sucessive invoice contacts, because they are going to be reverted to the first invoice contact.

Regards.

review: Needs Fixing
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Pedro,

did you check the address_get() method in base/res/res_partner.py? Seems to me that this method does exactly what you request.

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

Hi, Stefan,

Indeed, it works. I didn't try the module and reading only the module code I saw that problem, but address_get() resolves it.

Sorry for bothering you.

Regards.

review: Approve (code review and test)
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

@Pedro: no bother at all, thanks for the review!

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

I'm setting this to 'Needs freview again' after the related bug on openobject-addons has reluctantly been confirmed some months ago with 'low' priority. I could propose to OCB, but I would prefer to have this as an optional module now and see if this could get integrated in OpenERP 8.

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

#38 ... when selecting [what?] that ...
#89ff wouldn't the code be more clear if you did

my_new_partner_id = None
if partner_id:
  my_new_partner_id =

result = super(my_new_partner_id or partner_id)

if my_new_partner_id != partner_id:
  result[value]['partner_id'] = my_new_partner_id
?

It took me a while to convince myself that the current implementation can't run into recursion problems

review: Needs Fixing (code review)
22. By Stefan Rijnhart (Opener)

[FIX] Module description

23. By Stefan Rijnhart (Opener)

[IMP] Simplify the logic and remove nonsense restart of the inheritance
 chain. Fix class name capitalization

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Holger, thanks for the review!

I repaired the mangled module description and simplified the code. The complexity was on purpose to try and restart the inheritance chain with the new partner, but that would not have worked anyway as onchange overrides typically would inject their changes on the result of the super, based on the original input (the old partner).

Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'account_invoice_partner'
2=== added file 'account_invoice_partner/__init__.py'
3--- account_invoice_partner/__init__.py 1970-01-01 00:00:00 +0000
4+++ account_invoice_partner/__init__.py 2014-02-24 15:12:28 +0000
5@@ -0,0 +1,1 @@
6+import model
7
8=== added file 'account_invoice_partner/__openerp__.py'
9--- account_invoice_partner/__openerp__.py 1970-01-01 00:00:00 +0000
10+++ account_invoice_partner/__openerp__.py 2014-02-24 15:12:28 +0000
11@@ -0,0 +1,32 @@
12+# -*- coding: utf-8 -*-
13+##############################################################################
14+#
15+# OpenERP, Open Source Management Solution
16+# This module copyright (C) 2012-2013 Therp BV (<http://therp.nl>).
17+#
18+# This program is free software: you can redistribute it and/or modify
19+# it under the terms of the GNU Affero General Public License as
20+# published by the Free Software Foundation, either version 3 of the
21+# License, or (at your option) any later version.
22+#
23+# This program is distributed in the hope that it will be useful,
24+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+# GNU Affero General Public License for more details.
27+#
28+# You should have received a copy of the GNU Affero General Public License
29+# along with this program. If not, see <http://www.gnu.org/licenses/>.
30+#
31+##############################################################################
32+{
33+ "name" : "Automatically select invoicing partner on invoice",
34+ "version" : "0.1",
35+ "author" : "Therp BV",
36+ "category": 'Accounting & Finance',
37+ "description": """
38+On an invoice, when selecting a partner of any other type than 'invoice',
39+replace the partner by an invoice contact if found.
40+ """,
41+ 'website': 'https://launchpad.net/account-invoicing',
42+ 'depends' : ['account'],
43+}
44
45=== added directory 'account_invoice_partner/model'
46=== added file 'account_invoice_partner/model/__init__.py'
47--- account_invoice_partner/model/__init__.py 1970-01-01 00:00:00 +0000
48+++ account_invoice_partner/model/__init__.py 2014-02-24 15:12:28 +0000
49@@ -0,0 +1,1 @@
50+import account_invoice
51
52=== added file 'account_invoice_partner/model/account_invoice.py'
53--- account_invoice_partner/model/account_invoice.py 1970-01-01 00:00:00 +0000
54+++ account_invoice_partner/model/account_invoice.py 2014-02-24 15:12:28 +0000
55@@ -0,0 +1,44 @@
56+# -*- coding: utf-8 -*-
57+##############################################################################
58+#
59+# OpenERP, Open Source Management Solution
60+# This module copyright (C) 2013 Therp BV (<http://therp.nl>).
61+#
62+# This program is free software: you can redistribute it and/or modify
63+# it under the terms of the GNU Affero General Public License as
64+# published by the Free Software Foundation, either version 3 of the
65+# License, or (at your option) any later version.
66+#
67+# This program is distributed in the hope that it will be useful,
68+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70+# GNU Affero General Public License for more details.
71+#
72+# You should have received a copy of the GNU Affero General Public License
73+# along with this program. If not, see <http://www.gnu.org/licenses/>.
74+#
75+##############################################################################
76+from openerp.osv import orm
77+
78+
79+class AccountInvoice(orm.Model):
80+ _inherit = 'account.invoice'
81+
82+ def onchange_partner_id(
83+ self, cr, uid, ids, type, partner_id,
84+ date_invoice=False, payment_term=False,
85+ partner_bank_id=False, company_id=False):
86+ """
87+ Replace the selected partner with the preferred invoice contact
88+ """
89+ partner_invoice_id = partner_id
90+ if partner_id:
91+ partner_invoice_id = self.pool.get('res.partner').address_get(
92+ cr, uid, [partner_id], adr_pref=['invoice'])['invoice']
93+ result = super(AccountInvoice, self).onchange_partner_id(
94+ cr, uid, ids, type, partner_invoice_id,
95+ date_invoice=date_invoice, payment_term=payment_term,
96+ partner_bank_id=partner_bank_id, company_id=company_id)
97+ if partner_invoice_id != partner_id:
98+ result['value']['partner_id'] = partner_invoice_id
99+ return result

Subscribers

People subscribed via source and target branches