Merge lp:~camptocamp/banking-addons/bank-statement-reconcile-70-voucher-killer into lp:banking-addons/bank-statement-reconcile-70

Proposed by Nicolas Bessi - Camptocamp
Status: Merged
Merged at revision: 84
Proposed branch: lp:~camptocamp/banking-addons/bank-statement-reconcile-70-voucher-killer
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 339 lines (+303/-0)
7 files modified
invoicing_voucher_killer/__init__.py (+20/-0)
invoicing_voucher_killer/__openerp__.py (+39/-0)
invoicing_voucher_killer/invoice_data.xml (+7/-0)
invoicing_voucher_killer/invoice_view.xml (+48/-0)
statement_voucher_killer/__init__.py (+21/-0)
statement_voucher_killer/__openerp__.py (+40/-0)
statement_voucher_killer/voucher.py (+128/-0)
To merge this branch: bzr merge lp:~camptocamp/banking-addons/bank-statement-reconcile-70-voucher-killer
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review, no test Approve
Yannick Vaucher @ Camptocamp Abstain
Review via email: mp+148434@code.launchpad.net

Description of the change

Adds two add-ons that prevent voucher to interfer with the statement ext related add-ons flow.

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

Hi,

Thanks for this MP. Just my 2 cents: it would be very much appreciated that you note with a comment where do you remove the voucher generation in the 2 overridden function in line : 241 and 303 and let the commented code. Something like:

# --- Start remove of voucher generation
# commented code
# --- End remove of voucher generation

This way, it'll be easier to port/maintain when hook will be available...

What do you think ?

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Well it may be quite ugly as I had to reindent the code and we will have more comment that actual code for the payment order. This will diminish readability. But I agree for small change set it is a good idea.

Regards

Nicolas

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

I may attach a diff file in module ??

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Couldn't be voucher be named by something else ? :/

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

That's really a personal taste, but I really dislike the usage of ##### for the reStructuredText title ;-)

typos:
l.195
s/normaly/normally/

l.196
s/draf/draft/

Haven't we a smart way to disable the voucher without overriding all this stuff?
For instance, return early from `account_voucher.create` and `account_voucher_line.create` when a specific key is given in the context? Thus we would just have to add this key from the wizards. Did you tried something in thoses lines?

review: Needs Information
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,
Well, thats a goog point you asked here.
In fact I have started with a base_voucher_killer addon that does almost the same as your proposition.

It worked well with account.statement.from.invoice.lines but the structure of the code of other function break totally this approach. Maybe we can keep an hybrid approach.

Any opinion about it?

84. By Nicolas Bessi - Camptocamp

[TYPOS]

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Typos corrected

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

LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'invoicing_voucher_killer'
2=== added file 'invoicing_voucher_killer/__init__.py'
3--- invoicing_voucher_killer/__init__.py 1970-01-01 00:00:00 +0000
4+++ invoicing_voucher_killer/__init__.py 2013-02-28 12:50:27 +0000
5@@ -0,0 +1,20 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Copyright (c) 2013 Camptocamp SA (http://www.camptocamp.com)
10+# @author Nicolas Bessi
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU Affero General Public License as
14+# published by the Free Software Foundation, either version 3 of the
15+# License, or (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Affero General Public License for more details.
21+#
22+# You should have received a copy of the GNU Affero General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26
27=== added file 'invoicing_voucher_killer/__openerp__.py'
28--- invoicing_voucher_killer/__openerp__.py 1970-01-01 00:00:00 +0000
29+++ invoicing_voucher_killer/__openerp__.py 2013-02-28 12:50:27 +0000
30@@ -0,0 +1,39 @@
31+# -*- coding: utf-8 -*-
32+##############################################################################
33+#
34+# Copyright (c) 2013 Camptocamp SA (http://www.camptocamp.com)
35+# @author Nicolas Bessi
36+#
37+# This program is free software: you can redistribute it and/or modify
38+# it under the terms of the GNU Affero General Public License as
39+# published by the Free Software Foundation, either version 3 of the
40+# License, or (at your option) any later version.
41+#
42+# This program is distributed in the hope that it will be useful,
43+# but WITHOUT ANY WARRANTY; without even the implied warranty of
44+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45+# GNU Affero General Public License for more details.
46+#
47+# You should have received a copy of the GNU Affero General Public License
48+# along with this program. If not, see <http://www.gnu.org/licenses/>.
49+#
50+##############################################################################
51+
52+{'name': 'Invoicing voucher killer',
53+ 'version': '1.0.0',
54+ 'category': 'other',
55+ 'description': """
56+Prevent the usage of voucher from invoices
57+##########################################
58+This add-on will disable "Register Payment" button
59+""",
60+ 'author': 'Camptocamp',
61+ 'website': 'http://www.camptocamp.com',
62+ 'depends': ['account_voucher'],
63+ 'data': ['invoice_data.xml',
64+ 'invoice_view.xml'],
65+ 'demo_xml': [],
66+ 'test': [],
67+ 'installable': True,
68+ 'active': False,
69+ }
70
71=== added file 'invoicing_voucher_killer/invoice_data.xml'
72--- invoicing_voucher_killer/invoice_data.xml 1970-01-01 00:00:00 +0000
73+++ invoicing_voucher_killer/invoice_data.xml 2013-02-28 12:50:27 +0000
74@@ -0,0 +1,7 @@
75+<openerp>
76+ <data>
77+ <record id="invoice_voucher_user" model="res.groups">
78+ <field name="name">Use voucher in Invoices</field>
79+ </record>
80+ </data>
81+</openerp>
82
83=== added file 'invoicing_voucher_killer/invoice_view.xml'
84--- invoicing_voucher_killer/invoice_view.xml 1970-01-01 00:00:00 +0000
85+++ invoicing_voucher_killer/invoice_view.xml 2013-02-28 12:50:27 +0000
86@@ -0,0 +1,48 @@
87+<openerp>
88+ <data>
89+ <record id="invoice_voucher_group" model="ir.ui.view">
90+ <field name="name">Hide voucher in invoice</field>
91+ <field name="model">account.invoice</field>
92+ <field name="inherit_id" ref="account_voucher.view_invoice_customer" />
93+ <field name="type">form</field>
94+ <field name="arch" type="xml">
95+ <xpath expr="//button[@name='invoice_pay_customer'][last()]"
96+ position="replace">
97+ <button name="invoice_pay_customer"
98+ type="object"
99+ string="Register Payment"
100+ attrs="{'invisible': ['|', ('state','!=','open'), ('sent','=',True)]}"
101+ groups="invoicing_voucher_killer.invoice_voucher_user"/>
102+ </xpath>
103+ <xpath expr="//button[@name='invoice_pay_customer'][1]"
104+ position="replace">
105+ <button name="invoice_pay_customer"
106+ type="object"
107+ string="Register Payment"
108+ attrs="{'invisible': ['|', ('state','!=','open'), ('sent','=',False)]}"
109+ class="oe_highlight"
110+ groups="invoicing_voucher_killer.invoice_voucher_user"/>
111+ </xpath>
112+ </field>
113+ </record>
114+
115+ <record id="invoice_voucher_group_supp_inv" model="ir.ui.view">
116+ <field name="name">Hide voucher in supplier invoice</field>
117+ <field name="model">account.invoice</field>
118+ <field name="inherit_id" ref="account_voucher.view_invoice_supplier" />
119+ <field name="type">form</field>
120+ <field name="arch" type="xml">
121+ <xpath expr="//button[@name='invoice_pay_customer'][last()]"
122+ position="replace">
123+ <button name="invoice_pay_customer"
124+ type="object"
125+ string="Pay"
126+ states="open"
127+ class="oe_highlight"
128+ groups="invoicing_voucher_killer.invoice_voucher_user"/>
129+ </xpath>
130+ </field>
131+ </record>
132+
133+ </data>
134+</openerp>
135
136=== added directory 'statement_voucher_killer'
137=== added file 'statement_voucher_killer/__init__.py'
138--- statement_voucher_killer/__init__.py 1970-01-01 00:00:00 +0000
139+++ statement_voucher_killer/__init__.py 2013-02-28 12:50:27 +0000
140@@ -0,0 +1,21 @@
141+# -*- coding: utf-8 -*-
142+##############################################################################
143+#
144+# Copyright (c) 2013 Camptocamp SA (http://www.camptocamp.com)
145+# @author Nicolas Bessi
146+#
147+# This program is free software: you can redistribute it and/or modify
148+# it under the terms of the GNU Affero General Public License as
149+# published by the Free Software Foundation, either version 3 of the
150+# License, or (at your option) any later version.
151+#
152+# This program is distributed in the hope that it will be useful,
153+# but WITHOUT ANY WARRANTY; without even the implied warranty of
154+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155+# GNU Affero General Public License for more details.
156+#
157+# You should have received a copy of the GNU Affero General Public License
158+# along with this program. If not, see <http://www.gnu.org/licenses/>.
159+#
160+##############################################################################
161+from . import voucher
162
163=== added file 'statement_voucher_killer/__openerp__.py'
164--- statement_voucher_killer/__openerp__.py 1970-01-01 00:00:00 +0000
165+++ statement_voucher_killer/__openerp__.py 2013-02-28 12:50:27 +0000
166@@ -0,0 +1,40 @@
167+# -*- coding: utf-8 -*-
168+##############################################################################
169+#
170+# Copyright (c) 2013 Camptocamp SA (http://www.camptocamp.com)
171+# @author Nicolas Bessi
172+#
173+# This program is free software: you can redistribute it and/or modify
174+# it under the terms of the GNU Affero General Public License as
175+# published by the Free Software Foundation, either version 3 of the
176+# License, or (at your option) any later version.
177+#
178+# This program is distributed in the hope that it will be useful,
179+# but WITHOUT ANY WARRANTY; without even the implied warranty of
180+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
181+# GNU Affero General Public License for more details.
182+#
183+# You should have received a copy of the GNU Affero General Public License
184+# along with this program. If not, see <http://www.gnu.org/licenses/>.
185+#
186+##############################################################################
187+
188+{'name': 'voucher killer',
189+ 'version': '1.0.0',
190+ 'category': 'other',
191+ 'description': """
192+Prevent voucher creation when importing lines into statement.
193+#############################################################
194+
195+When importing invoice or payment into a bank statement or a payment order, normally a
196+draft voucher is created on the line. This module will disable this voucher creation""",
197+ 'author': 'Camptocamp',
198+ 'website': 'http://www.camptocamp.com',
199+ 'depends': ['account_voucher', 'account_payment'],
200+ 'init_xml': [],
201+ 'update_xml': [],
202+ 'demo_xml': [],
203+ 'test': [],
204+ 'installable': True,
205+ 'active': False,
206+ }
207
208=== added file 'statement_voucher_killer/voucher.py'
209--- statement_voucher_killer/voucher.py 1970-01-01 00:00:00 +0000
210+++ statement_voucher_killer/voucher.py 2013-02-28 12:50:27 +0000
211@@ -0,0 +1,128 @@
212+# -*- coding: utf-8 -*-
213+##############################################################################
214+#
215+# Copyright (c) 2013 Camptocamp SA (http://www.camptocamp.com)
216+# @author Nicolas Bessi
217+#
218+# This program is free software: you can redistribute it and/or modify
219+# it under the terms of the GNU Affero General Public License as
220+# published by the Free Software Foundation, either version 3 of the
221+# License, or (at your option) any later version.
222+#
223+# This program is distributed in the hope that it will be useful,
224+# but WITHOUT ANY WARRANTY; without even the implied warranty of
225+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
226+# GNU Affero General Public License for more details.
227+#
228+# You should have received a copy of the GNU Affero General Public License
229+# along with this program. If not, see <http://www.gnu.org/licenses/>.
230+#
231+##############################################################################
232+from openerp.osv import orm
233+
234+import time
235+
236+
237+class AccountStatementFromInvoiceLines(orm.TransientModel):
238+
239+ _inherit = "account.statement.from.invoice.lines"
240+
241+ def populate_statement(self, cr, uid, ids, context=None):
242+ """Taken from account voucher as no hook is available. No function
243+ no refactoring, just trimming the part that generates voucher"""
244+ if context is None:
245+ context = {}
246+ statement_id = context.get('statement_id', False)
247+ if not statement_id:
248+ return {'type': 'ir.actions.act_window_close'}
249+ data = self.read(cr, uid, ids, context=context)[0]
250+ line_ids = data['line_ids']
251+ if not line_ids:
252+ return {'type': 'ir.actions.act_window_close'}
253+
254+ line_obj = self.pool.get('account.move.line')
255+ statement_obj = self.pool.get('account.bank.statement')
256+ statement_line_obj = self.pool.get('account.bank.statement.line')
257+ currency_obj = self.pool.get('res.currency')
258+ line_date = time.strftime('%Y-%m-%d')
259+ statement = statement_obj.browse(cr, uid, statement_id, context=context)
260+ # for each selected move lines
261+ for line in line_obj.browse(cr, uid, line_ids, context=context):
262+ ctx = context.copy()
263+ # take the date for computation of currency => use payment date
264+ ctx['date'] = line_date
265+ amount = 0.0
266+
267+ if line.debit > 0:
268+ amount = line.debit
269+ elif line.credit > 0:
270+ amount = -line.credit
271+
272+ if line.amount_currency:
273+ amount = currency_obj.compute(cr, uid, line.currency_id.id,
274+ statement.currency.id, line.amount_currency, context=ctx)
275+ elif (line.invoice and line.invoice.currency_id.id <> statement.currency.id):
276+ amount = currency_obj.compute(cr, uid, line.invoice.currency_id.id,
277+ statement.currency.id, amount, context=ctx)
278+
279+ context.update({'move_line_ids': [line.id],
280+ 'invoice_id': line.invoice.id})
281+ s_type = 'general'
282+ if line.journal_id.type in ('sale', 'sale_refund'):
283+ s_type = 'customer'
284+ elif line.journal_id.type in ('purchase', 'purhcase_refund'):
285+ s_type = 'supplier'
286+ statement_line_obj.create(cr, uid, {
287+ 'name': line.name or '?',
288+ 'amount': amount,
289+ 'type': s_type,
290+ 'partner_id': line.partner_id.id,
291+ 'account_id': line.account_id.id,
292+ 'statement_id': statement_id,
293+ 'ref': line.ref,
294+ 'voucher_id': False,
295+ 'date': time.strftime('%Y-%m-%d'),
296+ }, context=context)
297+ return {'type': 'ir.actions.act_window_close'}
298+
299+
300+class AccountPaymentPopulateStatement(orm.TransientModel):
301+ _inherit = "account.payment.populate.statement"
302+
303+ def populate_statement(self, cr, uid, ids, context=None):
304+ """Taken from payment addon as no hook is vailable. No function
305+ no refactoring, just trimming the part that generates voucher"""
306+ line_obj = self.pool.get('payment.line')
307+ statement_obj = self.pool.get('account.bank.statement')
308+ statement_line_obj = self.pool.get('account.bank.statement.line')
309+ currency_obj = self.pool.get('res.currency')
310+
311+ if context is None:
312+ context = {}
313+ data = self.read(cr, uid, ids, [], context=context)[0]
314+ line_ids = data['lines']
315+ if not line_ids:
316+ return {'type': 'ir.actions.act_window_close'}
317+
318+ statement = statement_obj.browse(cr, uid, context['active_id'], context=context)
319+
320+ for line in line_obj.browse(cr, uid, line_ids, context=context):
321+ ctx = context.copy()
322+ ctx['date'] = line.ml_maturity_date # was value_date earlier,but this field exists no more now
323+ amount = currency_obj.compute(cr, uid, line.currency.id,
324+ statement.currency.id, line.amount_currency, context=ctx)
325+ if not line.move_line_id.id:
326+ continue
327+ context.update({'move_line_ids': [line.move_line_id.id]})
328+ st_line_id = statement_line_obj.create(cr, uid, {
329+ 'name': line.order_id.reference or '?',
330+ 'amount': - amount,
331+ 'type': 'supplier',
332+ 'partner_id': line.partner_id.id,
333+ 'account_id': line.move_line_id.account_id.id,
334+ 'statement_id': statement.id,
335+ 'ref': line.communication,
336+ }, context=context)
337+
338+ line_obj.write(cr, uid, [line.id], {'bank_statement_line_id': st_line_id})
339+ return {'type': 'ir.actions.act_window_close'}

Subscribers

People subscribed via source and target branches