Merge lp:~camptocamp/e-commerce-addons/7.0-receivable_account_payment_method-rde into lp:~extra-addons-commiter/e-commerce-addons/7.0

Proposed by Romain Deheele - Camptocamp
Status: Needs review
Proposed branch: lp:~camptocamp/e-commerce-addons/7.0-receivable_account_payment_method-rde
Merge into: lp:~extra-addons-commiter/e-commerce-addons/7.0
Diff against target: 484 lines (+431/-0)
10 files modified
receivable_account_payment_method/__init__.py (+22/-0)
receivable_account_payment_method/__openerp__.py (+48/-0)
receivable_account_payment_method/account_invoice.py (+75/-0)
receivable_account_payment_method/account_invoice_view.xml (+39/-0)
receivable_account_payment_method/i18n/fr.po (+48/-0)
receivable_account_payment_method/i18n/receivable_account_payment_method.pot (+48/-0)
receivable_account_payment_method/payment_method.py (+32/-0)
receivable_account_payment_method/payment_method_view.xml (+26/-0)
receivable_account_payment_method/sale.py (+50/-0)
receivable_account_payment_method/test/receivable_account_payment_method.yml (+43/-0)
To merge this branch: bzr merge lp:~camptocamp/e-commerce-addons/7.0-receivable_account_payment_method-rde
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Needs Resubmitting
Joël Grand-Guillaume @ camptocamp code review, no tests Needs Fixing
Review via email: mp+223738@code.launchpad.net

Description of the change

Hello,

Here is a new addon to define a default receivable account on a payment method.
Goal : when an invoice is generated with this payment method, account_id on customer invoice
is populated according to this default receivable account.
Infos:
 - new field payment_method_id on invoice (sale payment method is propagated on invoice at confirmation)
 - partner and payment method changes are managed : if there is no payment method on invoice or no default receivable account on selected payment method, default receivable account set on partner is chosen.

Regards,

Romain

To post a comment you must log in.
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

Thanks a lot for this module ! We even have some tests, great !

Little things to change:

 * L136: No context=context for the .browse

Then, I would really find useful to add a group_by payment_method in the invoices search view. This way, in a few click, you know for example the amount by payment_method on open invoices and can compare with your "non-imported" bank statement.

Otherwise, perfect !

Joël

review: Needs Fixing (code review, no tests)
297. By Romain Deheele - Camptocamp

[UPD] test was deceptively green, need to create a manual invoice from the sale order

298. By Romain Deheele - Camptocamp

[UPD] add context on browse

299. By Romain Deheele - Camptocamp

[UPD] change test description

300. By Romain Deheele - Camptocamp

[UPD] Title underline too short in manifest

301. By Romain Deheele - Camptocamp

[ADD] Add filter by payment method on customer invoices

302. By Romain Deheele - Camptocamp

[UPD] display payment method on customer refund too

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Thanks Joel,

I add your suggestions.
I fix too another various things:
- fix the test
- display payment on customer refund too

Regards,

Romain

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

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

Unmerged revisions

302. By Romain Deheele - Camptocamp

[UPD] display payment method on customer refund too

301. By Romain Deheele - Camptocamp

[ADD] Add filter by payment method on customer invoices

300. By Romain Deheele - Camptocamp

[UPD] Title underline too short in manifest

299. By Romain Deheele - Camptocamp

[UPD] change test description

298. By Romain Deheele - Camptocamp

[UPD] add context on browse

297. By Romain Deheele - Camptocamp

[UPD] test was deceptively green, need to create a manual invoice from the sale order

296. By Romain Deheele - Camptocamp

[ADD] add receivable_account_payment_method addon : allows to define a default receivable account according to a payment method

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'receivable_account_payment_method'
2=== added file 'receivable_account_payment_method/__init__.py'
3--- receivable_account_payment_method/__init__.py 1970-01-01 00:00:00 +0000
4+++ receivable_account_payment_method/__init__.py 2014-06-20 13:14:11 +0000
5@@ -0,0 +1,22 @@
6+##############################################################################
7+#
8+# Author: Romain Deheele
9+# Copyright 2014 Camptocamp SA
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+from . import account_invoice
26+from . import payment_method
27+from . import sale
28
29=== added file 'receivable_account_payment_method/__openerp__.py'
30--- receivable_account_payment_method/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ receivable_account_payment_method/__openerp__.py 2014-06-20 13:14:11 +0000
32@@ -0,0 +1,48 @@
33+# -*- coding: utf-8 -*-
34+##############################################################################
35+#
36+# Author: Romain Deheele
37+# Copyright 2014 Camptocamp SA
38+#
39+# This program is free software: you can redistribute it and/or modify
40+# it under the terms of the GNU Affero General Public License as
41+# published by the Free Software Foundation, either version 3 of the
42+# License, or (at your option) any later version.
43+#
44+# This program is distributed in the hope that it will be useful,
45+# but WITHOUT ANY WARRANTY; without even the implied warranty of
46+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47+# GNU Affero General Public License for more details.
48+#
49+# You should have received a copy of the GNU Affero General Public License
50+# along with this program. If not, see <http://www.gnu.org/licenses/>.
51+#
52+##############################################################################
53+
54+{
55+ 'name': 'Receivable Account Payment Method',
56+ 'version': '0.1',
57+ 'category': 'Generic Modules/Others',
58+ 'license': 'AGPL-3',
59+ 'description': """
60+Receivable Account Payment Method
61+==================================
62+
63+This module adds possibility to configure
64+a default receivable account on a payment method:
65+
66+When a default receivable account is specified on a payment method,
67+an invoice using this payment method uses it instead of
68+receivable account defined on partner.
69+""",
70+ 'author': 'Camptocamp',
71+ 'website': 'http://www.camptocamp.com/',
72+ 'depends': ['sale_payment_method',
73+ ],
74+ 'data': ['account_invoice_view.xml',
75+ 'payment_method_view.xml',
76+ ],
77+ 'demo': [],
78+ 'test': ['test/receivable_account_payment_method.yml'],
79+ 'installable': True,
80+}
81
82=== added file 'receivable_account_payment_method/account_invoice.py'
83--- receivable_account_payment_method/account_invoice.py 1970-01-01 00:00:00 +0000
84+++ receivable_account_payment_method/account_invoice.py 2014-06-20 13:14:11 +0000
85@@ -0,0 +1,75 @@
86+# -*- coding: utf-8 -*-
87+##############################################################################
88+#
89+# Author: Romain Deheele
90+# Copyright 2014 Camptocamp SA
91+#
92+# This program is free software: you can redistribute it and/or modify
93+# it under the terms of the GNU Affero General Public License as
94+# published by the Free Software Foundation, either version 3 of the
95+# License, or (at your option) any later version.
96+#
97+# This program is distributed in the hope that it will be useful,
98+# but WITHOUT ANY WARRANTY; without even the implied warranty of
99+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100+# GNU Affero General Public License for more details.
101+#
102+# You should have received a copy of the GNU Affero General Public License
103+# along with this program. If not, see <http://www.gnu.org/licenses/>.
104+#
105+##############################################################################
106+
107+from openerp.osv import orm, fields
108+
109+
110+class account_invoice(orm.Model):
111+ _inherit = 'account.invoice'
112+
113+ _columns = {
114+ 'payment_method_id': fields.many2one(
115+ 'payment.method', 'Payment Method', readonly=True,
116+ states={'draft': [('readonly', False)]}
117+ ),
118+ }
119+
120+ def onchange_payment_method_id(self, cr, uid, ids, payment_method_id,
121+ type, partner_id, context=None):
122+ """Update account_id according to the account set on the payment_method
123+ else update account according to partner's receivable account
124+ """
125+ result = {}
126+ if type in ('out_invoice', 'out_refund'):
127+ if payment_method_id:
128+ payment_method = self.pool['payment.method'].\
129+ browse(cr, uid, payment_method_id, context=context)
130+ if payment_method.receivable_account_id:
131+ result = {'value': {
132+ 'account_id': payment_method.receivable_account_id.id
133+ }
134+ }
135+ if not result:
136+ p = self.pool['res.partner'].browse(cr, uid, partner_id,
137+ context=context)
138+ result = {'value': {
139+ 'account_id': p.property_account_receivable.id
140+ }
141+ }
142+ return result
143+
144+ def onchange_partner_id(self, cr, uid, ids, type, partner_id,
145+ date_invoice=False, payment_term=False,
146+ partner_bank_id=False, company_id=False,
147+ payment_method_id=False):
148+ """this override updates account_id according to the account set
149+ on payment_method
150+ """
151+ result = super(account_invoice, self).\
152+ onchange_partner_id(cr, uid, ids, type, partner_id, date_invoice,
153+ payment_term, partner_bank_id, company_id)
154+ if type in ('out_invoice', 'out_refund') and payment_method_id:
155+ payment_method = self.pool['payment.method'].\
156+ browse(cr, uid, payment_method_id)
157+ if payment_method.receivable_account_id:
158+ result['value']['account_id'] = \
159+ payment_method.receivable_account_id.id
160+ return result
161
162=== added file 'receivable_account_payment_method/account_invoice_view.xml'
163--- receivable_account_payment_method/account_invoice_view.xml 1970-01-01 00:00:00 +0000
164+++ receivable_account_payment_method/account_invoice_view.xml 2014-06-20 13:14:11 +0000
165@@ -0,0 +1,39 @@
166+<?xml version="1.0" encoding="utf-8"?>
167+<openerp>
168+ <data>
169+
170+ <!-- Form view -->
171+ <record id="view_customer_invoice_payment_method" model="ir.ui.view">
172+ <field name="name">account.invoice.add.payment_method</field>
173+ <field name="model">account.invoice</field>
174+ <field name="inherit_id" ref="account.invoice_form"/>
175+ <field name="arch" type="xml">
176+ <field name="partner_id" position="replace" version="7.0">
177+ <field string="Customer" name="partner_id"
178+ on_change="onchange_partner_id(type,partner_id,date_invoice,payment_term, partner_bank_id,company_id,payment_method_id)"
179+ groups="base.group_user" context="{'search_default_customer':1, 'show_address': 1}"
180+ options='{"always_reload": True}'
181+ domain="[('customer', '=', True)]"/>
182+ </field>
183+ <field name="payment_term" position="before" version="7.0">
184+ <field name="payment_method_id" on_change="onchange_payment_method_id(payment_method_id, type, partner_id, context)"
185+ attrs="{'invisible': [('type', 'not in', ('out_invoice','out_refund'))]}" class="oe_inline"/>
186+ </field>
187+ </field>
188+ </record>
189+
190+ <!-- Search view -->
191+ <record id="view_account_invoice_payment_method_filter" model="ir.ui.view">
192+ <field name="name">account.invoice.add.payment_method.filter</field>
193+ <field name="model">account.invoice</field>
194+ <field name="inherit_id" ref="account.view_account_invoice_filter"/>
195+ <field name="arch" type="xml">
196+ <filter string="Due Date" position="after">
197+ <filter string="Payment Method" icon="terp-go-month" domain="[]" context="{'group_by':'payment_method_id'}"/>
198+ </filter>
199+ </field>
200+ </record>
201+
202+ </data>
203+</openerp>
204+
205
206=== added directory 'receivable_account_payment_method/i18n'
207=== added file 'receivable_account_payment_method/i18n/fr.po'
208--- receivable_account_payment_method/i18n/fr.po 1970-01-01 00:00:00 +0000
209+++ receivable_account_payment_method/i18n/fr.po 2014-06-20 13:14:11 +0000
210@@ -0,0 +1,48 @@
211+# Translation of OpenERP Server.
212+# This file contains the translation of the following modules:
213+# * receivable_account_payment_method
214+#
215+msgid ""
216+msgstr ""
217+"Project-Id-Version: OpenERP Server 7.0\n"
218+"Report-Msgid-Bugs-To: \n"
219+"POT-Creation-Date: 2014-06-19 10:35+0000\n"
220+"PO-Revision-Date: 2014-06-19 10:35+0000\n"
221+"Last-Translator: <>\n"
222+"Language-Team: \n"
223+"MIME-Version: 1.0\n"
224+"Content-Type: text/plain; charset=UTF-8\n"
225+"Content-Transfer-Encoding: \n"
226+"Plural-Forms: \n"
227+
228+#. module: receivable_account_payment_method
229+#: view:account.invoice:0
230+msgid "Customer"
231+msgstr "Client"
232+
233+#. module: receivable_account_payment_method
234+#: field:payment.method,receivable_account_id:0
235+msgid "Account"
236+msgstr "Compte"
237+
238+#. module: receivable_account_payment_method
239+#: field:account.invoice,payment_method_id:0
240+#: model:ir.model,name:receivable_account_payment_method.model_payment_method
241+msgid "Payment Method"
242+msgstr "Méthode de paiement"
243+
244+#. module: receivable_account_payment_method
245+#: help:payment.method,receivable_account_id:0
246+msgid "The receivable account used for this payment method."
247+msgstr "Le compte client utilisé pour ce moyen de paiement."
248+
249+#. module: receivable_account_payment_method
250+#: model:ir.model,name:receivable_account_payment_method.model_account_invoice
251+msgid "Invoice"
252+msgstr "Facture"
253+
254+#. module: receivable_account_payment_method
255+#: model:ir.model,name:receivable_account_payment_method.model_sale_order
256+msgid "Sales Order"
257+msgstr "Bon de commande"
258+
259
260=== added file 'receivable_account_payment_method/i18n/receivable_account_payment_method.pot'
261--- receivable_account_payment_method/i18n/receivable_account_payment_method.pot 1970-01-01 00:00:00 +0000
262+++ receivable_account_payment_method/i18n/receivable_account_payment_method.pot 2014-06-20 13:14:11 +0000
263@@ -0,0 +1,48 @@
264+# Translation of OpenERP Server.
265+# This file contains the translation of the following modules:
266+# * receivable_account_payment_method
267+#
268+msgid ""
269+msgstr ""
270+"Project-Id-Version: OpenERP Server 7.0\n"
271+"Report-Msgid-Bugs-To: \n"
272+"POT-Creation-Date: 2014-06-19 10:34+0000\n"
273+"PO-Revision-Date: 2014-06-19 10:34+0000\n"
274+"Last-Translator: <>\n"
275+"Language-Team: \n"
276+"MIME-Version: 1.0\n"
277+"Content-Type: text/plain; charset=UTF-8\n"
278+"Content-Transfer-Encoding: \n"
279+"Plural-Forms: \n"
280+
281+#. module: receivable_account_payment_method
282+#: view:account.invoice:0
283+msgid "Customer"
284+msgstr ""
285+
286+#. module: receivable_account_payment_method
287+#: field:payment.method,receivable_account_id:0
288+msgid "Account"
289+msgstr ""
290+
291+#. module: receivable_account_payment_method
292+#: field:account.invoice,payment_method_id:0
293+#: model:ir.model,name:receivable_account_payment_method.model_payment_method
294+msgid "Payment Method"
295+msgstr ""
296+
297+#. module: receivable_account_payment_method
298+#: help:payment.method,receivable_account_id:0
299+msgid "The receivable account used for this payment method."
300+msgstr ""
301+
302+#. module: receivable_account_payment_method
303+#: model:ir.model,name:receivable_account_payment_method.model_account_invoice
304+msgid "Invoice"
305+msgstr ""
306+
307+#. module: receivable_account_payment_method
308+#: model:ir.model,name:receivable_account_payment_method.model_sale_order
309+msgid "Sales Order"
310+msgstr ""
311+
312
313=== added file 'receivable_account_payment_method/payment_method.py'
314--- receivable_account_payment_method/payment_method.py 1970-01-01 00:00:00 +0000
315+++ receivable_account_payment_method/payment_method.py 2014-06-20 13:14:11 +0000
316@@ -0,0 +1,32 @@
317+# -*- coding: utf-8 -*-
318+##############################################################################
319+#
320+# Author: Romain Deheele
321+# Copyright 2014 Camptocamp SA
322+#
323+# This program is free software: you can redistribute it and/or modify
324+# it under the terms of the GNU Affero General Public License as
325+# published by the Free Software Foundation, either version 3 of the
326+# License, or (at your option) any later version.
327+#
328+# This program is distributed in the hope that it will be useful,
329+# but WITHOUT ANY WARRANTY; without even the implied warranty of
330+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
331+# GNU Affero General Public License for more details.
332+#
333+# You should have received a copy of the GNU Affero General Public License
334+# along with this program. If not, see <http://www.gnu.org/licenses/>.
335+#
336+##############################################################################
337+
338+from openerp.osv import fields, orm
339+
340+
341+class payment_method(orm.Model):
342+ _inherit = "payment.method"
343+
344+ _columns = {
345+ 'receivable_account_id': fields.many2one(
346+ 'account.account', 'Account', domain=[('type', '=', 'receivable')],
347+ help="The receivable account used for this payment method."),
348+ }
349
350=== added file 'receivable_account_payment_method/payment_method_view.xml'
351--- receivable_account_payment_method/payment_method_view.xml 1970-01-01 00:00:00 +0000
352+++ receivable_account_payment_method/payment_method_view.xml 2014-06-20 13:14:11 +0000
353@@ -0,0 +1,26 @@
354+<?xml version="1.0" encoding="utf-8"?>
355+<openerp>
356+ <data>
357+
358+ <!-- VIEW FOR THE OBJECT : payment_method -->
359+ <record id="payment_method_view_form" model="ir.ui.view">
360+ <field name="name">receivable_account_payment_method.payment_method.view_form</field>
361+ <field name="model">payment.method</field>
362+ <field name="inherit_id" ref="sale_payment_method.payment_method_view_form" />
363+ <field name="arch" type="xml">
364+ <field name="payment_term_id" position="after">
365+ <group>
366+ <field name="receivable_account_id" />
367+ </group>
368+ <group name="payment_help" class="oe_grey" col="1">
369+ <p attrs="{'invisible': [('receivable_account_id', '=', False)]}">
370+ Invoice using this payment method
371+ will use this account as receivable account.
372+ </p>
373+ </group>
374+ </field>
375+ </field>
376+ </record>
377+
378+ </data>
379+</openerp>
380\ No newline at end of file
381
382=== added file 'receivable_account_payment_method/sale.py'
383--- receivable_account_payment_method/sale.py 1970-01-01 00:00:00 +0000
384+++ receivable_account_payment_method/sale.py 2014-06-20 13:14:11 +0000
385@@ -0,0 +1,50 @@
386+# -*- coding: utf-8 -*-
387+##############################################################################
388+#
389+# Author: Romain Deheele
390+# Copyright 2014 Camptocamp SA
391+#
392+# This program is free software: you can redistribute it and/or modify
393+# it under the terms of the GNU Affero General Public License as
394+# published by the Free Software Foundation, either version 3 of the
395+# License, or (at your option) any later version.
396+#
397+# This program is distributed in the hope that it will be useful,
398+# but WITHOUT ANY WARRANTY; without even the implied warranty of
399+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
400+# GNU Affero General Public License for more details.
401+#
402+# You should have received a copy of the GNU Affero General Public License
403+# along with this program. If not, see <http://www.gnu.org/licenses/>.
404+#
405+##############################################################################
406+
407+from openerp.osv import orm
408+
409+
410+class sale_order(orm.Model):
411+ _inherit = 'sale.order'
412+
413+ def _prepare_invoice(self, cr, uid, order, lines, context=None):
414+ """Alter prepared values according to payment_method and
415+ possible default receivable account set on payment method
416+ Original function prepares the dict of values to create
417+ the new invoice for a sales order.
418+
419+ :param browse_record order: sale.order record to invoice
420+ :param list(int) line: list of invoice line IDs that must be
421+ attached to the invoice
422+ :return: dict of value to create() the invoice
423+ """
424+ if context is None:
425+ context = {}
426+ invoice_vals = super(sale_order, self).\
427+ _prepare_invoice(cr, uid, order, lines, context=context)
428+ if order.payment_method_id:
429+ if order.payment_method_id.receivable_account_id:
430+ payment_method = order.payment_method_id
431+ invoice_vals.update({
432+ 'account_id': payment_method.receivable_account_id.id,
433+ 'payment_method_id': payment_method.id
434+ })
435+ return invoice_vals
436
437=== added directory 'receivable_account_payment_method/test'
438=== added file 'receivable_account_payment_method/test/receivable_account_payment_method.yml'
439--- receivable_account_payment_method/test/receivable_account_payment_method.yml 1970-01-01 00:00:00 +0000
440+++ receivable_account_payment_method/test/receivable_account_payment_method.yml 2014-06-20 13:14:11 +0000
441@@ -0,0 +1,43 @@
442+-
443+ I create a new receivable account
444+-
445+ !record {model: account.account, id: paypal_account}:
446+ code: 110201
447+ name: Debtors Paypal
448+ type: receivable
449+ user_type: account.data_account_type_receivable
450+-
451+ I create a payment method
452+-
453+ !record {model: payment.method, id: paypal_method}:
454+ name: Paypal
455+ receivable_account_id: paypal_account
456+-
457+ I create a sale order with paypal payment method
458+-
459+ !record {model: sale.order, id: sale_order_paypal}:
460+ name: My paypal order
461+ partner_id: base.res_partner_12
462+ payment_method_id: paypal_method
463+ order_line:
464+ - product_id: product.product_product_6
465+ product_uom_qty: 2
466+-
467+ I confirm the sale order
468+-
469+ !workflow {model: sale.order, action: order_confirm, ref: sale_order_paypal}
470+-
471+ I create a manual invoice from the confirmed sale order.
472+-
473+ !python {model: sale.advance.payment.inv}: |
474+ ctx = context.copy()
475+ ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale_order_paypal")], "active_id":ref("sale_order_paypal")})
476+ pay_id = self.create(cr, uid, {'advance_payment_method': 'all'})
477+ self.create_invoices(cr, uid, [pay_id], context=ctx)
478+-
479+ I check the receivable account on the generated invoice.
480+-
481+ !python {model: sale.order}: |
482+ invoice_ids = self.browse(cr, uid, ref("sale_order_paypal")).invoice_ids
483+ for invoice in invoice_ids:
484+ assert invoice.account_id.id == ref("paypal_account")

Subscribers

People subscribed via source and target branches