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
=== added directory 'receivable_account_payment_method'
=== added file 'receivable_account_payment_method/__init__.py'
--- receivable_account_payment_method/__init__.py 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/__init__.py 2014-06-20 13:14:11 +0000
@@ -0,0 +1,22 @@
1##############################################################################
2#
3# Author: Romain Deheele
4# Copyright 2014 Camptocamp SA
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19##############################################################################
20from . import account_invoice
21from . import payment_method
22from . import sale
023
=== added file 'receivable_account_payment_method/__openerp__.py'
--- receivable_account_payment_method/__openerp__.py 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/__openerp__.py 2014-06-20 13:14:11 +0000
@@ -0,0 +1,48 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22{
23 'name': 'Receivable Account Payment Method',
24 'version': '0.1',
25 'category': 'Generic Modules/Others',
26 'license': 'AGPL-3',
27 'description': """
28Receivable Account Payment Method
29==================================
30
31This module adds possibility to configure
32a default receivable account on a payment method:
33
34When a default receivable account is specified on a payment method,
35an invoice using this payment method uses it instead of
36receivable account defined on partner.
37""",
38 'author': 'Camptocamp',
39 'website': 'http://www.camptocamp.com/',
40 'depends': ['sale_payment_method',
41 ],
42 'data': ['account_invoice_view.xml',
43 'payment_method_view.xml',
44 ],
45 'demo': [],
46 'test': ['test/receivable_account_payment_method.yml'],
47 'installable': True,
48}
049
=== added file 'receivable_account_payment_method/account_invoice.py'
--- receivable_account_payment_method/account_invoice.py 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/account_invoice.py 2014-06-20 13:14:11 +0000
@@ -0,0 +1,75 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import orm, fields
23
24
25class account_invoice(orm.Model):
26 _inherit = 'account.invoice'
27
28 _columns = {
29 'payment_method_id': fields.many2one(
30 'payment.method', 'Payment Method', readonly=True,
31 states={'draft': [('readonly', False)]}
32 ),
33 }
34
35 def onchange_payment_method_id(self, cr, uid, ids, payment_method_id,
36 type, partner_id, context=None):
37 """Update account_id according to the account set on the payment_method
38 else update account according to partner's receivable account
39 """
40 result = {}
41 if type in ('out_invoice', 'out_refund'):
42 if payment_method_id:
43 payment_method = self.pool['payment.method'].\
44 browse(cr, uid, payment_method_id, context=context)
45 if payment_method.receivable_account_id:
46 result = {'value': {
47 'account_id': payment_method.receivable_account_id.id
48 }
49 }
50 if not result:
51 p = self.pool['res.partner'].browse(cr, uid, partner_id,
52 context=context)
53 result = {'value': {
54 'account_id': p.property_account_receivable.id
55 }
56 }
57 return result
58
59 def onchange_partner_id(self, cr, uid, ids, type, partner_id,
60 date_invoice=False, payment_term=False,
61 partner_bank_id=False, company_id=False,
62 payment_method_id=False):
63 """this override updates account_id according to the account set
64 on payment_method
65 """
66 result = super(account_invoice, self).\
67 onchange_partner_id(cr, uid, ids, type, partner_id, date_invoice,
68 payment_term, partner_bank_id, company_id)
69 if type in ('out_invoice', 'out_refund') and payment_method_id:
70 payment_method = self.pool['payment.method'].\
71 browse(cr, uid, payment_method_id)
72 if payment_method.receivable_account_id:
73 result['value']['account_id'] = \
74 payment_method.receivable_account_id.id
75 return result
076
=== added file 'receivable_account_payment_method/account_invoice_view.xml'
--- receivable_account_payment_method/account_invoice_view.xml 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/account_invoice_view.xml 2014-06-20 13:14:11 +0000
@@ -0,0 +1,39 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <!-- Form view -->
6 <record id="view_customer_invoice_payment_method" model="ir.ui.view">
7 <field name="name">account.invoice.add.payment_method</field>
8 <field name="model">account.invoice</field>
9 <field name="inherit_id" ref="account.invoice_form"/>
10 <field name="arch" type="xml">
11 <field name="partner_id" position="replace" version="7.0">
12 <field string="Customer" name="partner_id"
13 on_change="onchange_partner_id(type,partner_id,date_invoice,payment_term, partner_bank_id,company_id,payment_method_id)"
14 groups="base.group_user" context="{'search_default_customer':1, 'show_address': 1}"
15 options='{"always_reload": True}'
16 domain="[('customer', '=', True)]"/>
17 </field>
18 <field name="payment_term" position="before" version="7.0">
19 <field name="payment_method_id" on_change="onchange_payment_method_id(payment_method_id, type, partner_id, context)"
20 attrs="{'invisible': [('type', 'not in', ('out_invoice','out_refund'))]}" class="oe_inline"/>
21 </field>
22 </field>
23 </record>
24
25 <!-- Search view -->
26 <record id="view_account_invoice_payment_method_filter" model="ir.ui.view">
27 <field name="name">account.invoice.add.payment_method.filter</field>
28 <field name="model">account.invoice</field>
29 <field name="inherit_id" ref="account.view_account_invoice_filter"/>
30 <field name="arch" type="xml">
31 <filter string="Due Date" position="after">
32 <filter string="Payment Method" icon="terp-go-month" domain="[]" context="{'group_by':'payment_method_id'}"/>
33 </filter>
34 </field>
35 </record>
36
37 </data>
38</openerp>
39
040
=== added directory 'receivable_account_payment_method/i18n'
=== added file 'receivable_account_payment_method/i18n/fr.po'
--- receivable_account_payment_method/i18n/fr.po 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/i18n/fr.po 2014-06-20 13:14:11 +0000
@@ -0,0 +1,48 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * receivable_account_payment_method
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-06-19 10:35+0000\n"
10"PO-Revision-Date: 2014-06-19 10:35+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: receivable_account_payment_method
19#: view:account.invoice:0
20msgid "Customer"
21msgstr "Client"
22
23#. module: receivable_account_payment_method
24#: field:payment.method,receivable_account_id:0
25msgid "Account"
26msgstr "Compte"
27
28#. module: receivable_account_payment_method
29#: field:account.invoice,payment_method_id:0
30#: model:ir.model,name:receivable_account_payment_method.model_payment_method
31msgid "Payment Method"
32msgstr "Méthode de paiement"
33
34#. module: receivable_account_payment_method
35#: help:payment.method,receivable_account_id:0
36msgid "The receivable account used for this payment method."
37msgstr "Le compte client utilisé pour ce moyen de paiement."
38
39#. module: receivable_account_payment_method
40#: model:ir.model,name:receivable_account_payment_method.model_account_invoice
41msgid "Invoice"
42msgstr "Facture"
43
44#. module: receivable_account_payment_method
45#: model:ir.model,name:receivable_account_payment_method.model_sale_order
46msgid "Sales Order"
47msgstr "Bon de commande"
48
049
=== added file 'receivable_account_payment_method/i18n/receivable_account_payment_method.pot'
--- receivable_account_payment_method/i18n/receivable_account_payment_method.pot 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/i18n/receivable_account_payment_method.pot 2014-06-20 13:14:11 +0000
@@ -0,0 +1,48 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * receivable_account_payment_method
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-06-19 10:34+0000\n"
10"PO-Revision-Date: 2014-06-19 10:34+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: receivable_account_payment_method
19#: view:account.invoice:0
20msgid "Customer"
21msgstr ""
22
23#. module: receivable_account_payment_method
24#: field:payment.method,receivable_account_id:0
25msgid "Account"
26msgstr ""
27
28#. module: receivable_account_payment_method
29#: field:account.invoice,payment_method_id:0
30#: model:ir.model,name:receivable_account_payment_method.model_payment_method
31msgid "Payment Method"
32msgstr ""
33
34#. module: receivable_account_payment_method
35#: help:payment.method,receivable_account_id:0
36msgid "The receivable account used for this payment method."
37msgstr ""
38
39#. module: receivable_account_payment_method
40#: model:ir.model,name:receivable_account_payment_method.model_account_invoice
41msgid "Invoice"
42msgstr ""
43
44#. module: receivable_account_payment_method
45#: model:ir.model,name:receivable_account_payment_method.model_sale_order
46msgid "Sales Order"
47msgstr ""
48
049
=== added file 'receivable_account_payment_method/payment_method.py'
--- receivable_account_payment_method/payment_method.py 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/payment_method.py 2014-06-20 13:14:11 +0000
@@ -0,0 +1,32 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import fields, orm
23
24
25class payment_method(orm.Model):
26 _inherit = "payment.method"
27
28 _columns = {
29 'receivable_account_id': fields.many2one(
30 'account.account', 'Account', domain=[('type', '=', 'receivable')],
31 help="The receivable account used for this payment method."),
32 }
033
=== added file 'receivable_account_payment_method/payment_method_view.xml'
--- receivable_account_payment_method/payment_method_view.xml 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/payment_method_view.xml 2014-06-20 13:14:11 +0000
@@ -0,0 +1,26 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <!-- VIEW FOR THE OBJECT : payment_method -->
6 <record id="payment_method_view_form" model="ir.ui.view">
7 <field name="name">receivable_account_payment_method.payment_method.view_form</field>
8 <field name="model">payment.method</field>
9 <field name="inherit_id" ref="sale_payment_method.payment_method_view_form" />
10 <field name="arch" type="xml">
11 <field name="payment_term_id" position="after">
12 <group>
13 <field name="receivable_account_id" />
14 </group>
15 <group name="payment_help" class="oe_grey" col="1">
16 <p attrs="{'invisible': [('receivable_account_id', '=', False)]}">
17 Invoice using this payment method
18 will use this account as receivable account.
19 </p>
20 </group>
21 </field>
22 </field>
23 </record>
24
25 </data>
26</openerp>
0\ No newline at end of file27\ No newline at end of file
128
=== added file 'receivable_account_payment_method/sale.py'
--- receivable_account_payment_method/sale.py 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/sale.py 2014-06-20 13:14:11 +0000
@@ -0,0 +1,50 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Romain Deheele
5# Copyright 2014 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import orm
23
24
25class sale_order(orm.Model):
26 _inherit = 'sale.order'
27
28 def _prepare_invoice(self, cr, uid, order, lines, context=None):
29 """Alter prepared values according to payment_method and
30 possible default receivable account set on payment method
31 Original function prepares the dict of values to create
32 the new invoice for a sales order.
33
34 :param browse_record order: sale.order record to invoice
35 :param list(int) line: list of invoice line IDs that must be
36 attached to the invoice
37 :return: dict of value to create() the invoice
38 """
39 if context is None:
40 context = {}
41 invoice_vals = super(sale_order, self).\
42 _prepare_invoice(cr, uid, order, lines, context=context)
43 if order.payment_method_id:
44 if order.payment_method_id.receivable_account_id:
45 payment_method = order.payment_method_id
46 invoice_vals.update({
47 'account_id': payment_method.receivable_account_id.id,
48 'payment_method_id': payment_method.id
49 })
50 return invoice_vals
051
=== added directory 'receivable_account_payment_method/test'
=== added file 'receivable_account_payment_method/test/receivable_account_payment_method.yml'
--- receivable_account_payment_method/test/receivable_account_payment_method.yml 1970-01-01 00:00:00 +0000
+++ receivable_account_payment_method/test/receivable_account_payment_method.yml 2014-06-20 13:14:11 +0000
@@ -0,0 +1,43 @@
1-
2 I create a new receivable account
3-
4 !record {model: account.account, id: paypal_account}:
5 code: 110201
6 name: Debtors Paypal
7 type: receivable
8 user_type: account.data_account_type_receivable
9-
10 I create a payment method
11-
12 !record {model: payment.method, id: paypal_method}:
13 name: Paypal
14 receivable_account_id: paypal_account
15-
16 I create a sale order with paypal payment method
17-
18 !record {model: sale.order, id: sale_order_paypal}:
19 name: My paypal order
20 partner_id: base.res_partner_12
21 payment_method_id: paypal_method
22 order_line:
23 - product_id: product.product_product_6
24 product_uom_qty: 2
25-
26 I confirm the sale order
27-
28 !workflow {model: sale.order, action: order_confirm, ref: sale_order_paypal}
29-
30 I create a manual invoice from the confirmed sale order.
31-
32 !python {model: sale.advance.payment.inv}: |
33 ctx = context.copy()
34 ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale_order_paypal")], "active_id":ref("sale_order_paypal")})
35 pay_id = self.create(cr, uid, {'advance_payment_method': 'all'})
36 self.create_invoices(cr, uid, [pay_id], context=ctx)
37-
38 I check the receivable account on the generated invoice.
39-
40 !python {model: sale.order}: |
41 invoice_ids = self.browse(cr, uid, ref("sale_order_paypal")).invoice_ids
42 for invoice in invoice_ids:
43 assert invoice.account_id.id == ref("paypal_account")

Subscribers

People subscribed via source and target branches