Merge lp:~therp-nl/banking-addons/ba70-bank_statement_tax into lp:banking-addons

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 198
Proposed branch: lp:~therp-nl/banking-addons/ba70-bank_statement_tax
Merge into: lp:banking-addons
Diff against target: 239 lines (+207/-0)
6 files modified
account_bank_statement_tax/__init__.py (+1/-0)
account_bank_statement_tax/__openerp__.py (+43/-0)
account_bank_statement_tax/model/__init__.py (+2/-0)
account_bank_statement_tax/model/account_bank_statement.py (+109/-0)
account_bank_statement_tax/model/account_bank_statement_line.py (+34/-0)
account_bank_statement_tax/view/account_bank_statement.xml (+18/-0)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/ba70-bank_statement_tax
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Erwin van der Ploeg (BAS Solutions) (community) test Approve
Raphaël Valyi - http://www.akretion.com Approve
Review via email: mp+177376@code.launchpad.net

Description of the change

Generalized forward port (does not depend on account_banking) of http://bazaar.launchpad.net/~therp-nl/banking-addons/ba61-apply_tax_from_statement_line/revision/162, with added support for fiscal positions.

Thanks to BAS Solutions for funding part of the development!

To post a comment you must log in.
186. By Stefan Rijnhart (Opener)

[RFR] Don't repeat assignment within loop

187. By Stefan Rijnhart (Opener)

[RFR] Revert previous commit, problem between keyboard and chair

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

LGTM, no test

Eventually in account_bank_statement_tax/model/account_bank_statement.py from lines 118 to 127, fiscal position and mapping could be extracted in a sub-function that one could override. But I'm not sure yet if that would really fit for us, so we could always do that later.

That would also be interesting to see how this development relates (or not) with the "tax_on_payment" Anybox module here https://bitbucket.org/anybox/tax_on_payment/src/f34820153981fb7ac96bb2688483d2573db0756d/account.py?at=default
Basically they put a tax on the move at the reconciliation time while you put it when the bank statement is encoded. Not sure if the two things overlap or not.

review: Approve
Revision history for this message
Erwin van der Ploeg (BAS Solutions) (erwin-bassolutions-deactivatedaccount) wrote :

Made 2 new tax codes, with including tax. Tested the tax on bank statement. Accounting entries and tax statement are ok. Also tested the fiscal position. Also ok.

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

Hi Raphael,

thanks for the review! I think the anybox module has a distinct function: it seems to allow to move a previously calculated tax amount to a different account upon reconciliation (payment). The module leaves a lot implicit, for instance what a tax move line is (a move line on an account that has a 'due_payment' account configured).

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_bank_statement_tax'
2=== added file 'account_bank_statement_tax/__init__.py'
3--- account_bank_statement_tax/__init__.py 1970-01-01 00:00:00 +0000
4+++ account_bank_statement_tax/__init__.py 2013-10-06 19:03:39 +0000
5@@ -0,0 +1,1 @@
6+import model
7
8=== added file 'account_bank_statement_tax/__openerp__.py'
9--- account_bank_statement_tax/__openerp__.py 1970-01-01 00:00:00 +0000
10+++ account_bank_statement_tax/__openerp__.py 2013-10-06 19:03:39 +0000
11@@ -0,0 +1,43 @@
12+# -*- coding: utf-8 -*-
13+##############################################################################
14+#
15+# Copyright (C) 2012 - 2013 Therp BV (<http://therp.nl>).
16+# All Rights Reserved
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+{
34+ 'name': 'Apply a tax on bank statement lines',
35+ 'version': '0.1',
36+ 'license': 'AGPL-3',
37+ 'author': 'Therp BV',
38+ 'website': 'https://launchpad.net/banking-addons',
39+ 'category': 'Banking addons',
40+ 'depends': [
41+ 'account',
42+ ],
43+ 'data': [
44+ 'view/account_bank_statement.xml',
45+ ],
46+ 'description': '''
47+Allow an (inclusive) tax to be set on a bank statement line. When the
48+statement is confirmed, the tax will be processed like a tax set on a
49+move line.
50+
51+This module is co-funded by BAS Solutions.
52+ ''',
53+ 'installable': True,
54+}
55
56=== added directory 'account_bank_statement_tax/model'
57=== added file 'account_bank_statement_tax/model/__init__.py'
58--- account_bank_statement_tax/model/__init__.py 1970-01-01 00:00:00 +0000
59+++ account_bank_statement_tax/model/__init__.py 2013-10-06 19:03:39 +0000
60@@ -0,0 +1,2 @@
61+import account_bank_statement_line
62+import account_bank_statement
63
64=== added file 'account_bank_statement_tax/model/account_bank_statement.py'
65--- account_bank_statement_tax/model/account_bank_statement.py 1970-01-01 00:00:00 +0000
66+++ account_bank_statement_tax/model/account_bank_statement.py 2013-10-06 19:03:39 +0000
67@@ -0,0 +1,109 @@
68+# -*- coding: utf-8 -*-
69+##############################################################################
70+#
71+# Copyright (C) 2012 - 2013 Therp BV (<http://therp.nl>).
72+# All Rights Reserved
73+#
74+# This program is free software: you can redistribute it and/or modify
75+# it under the terms of the GNU Affero General Public License as
76+# published by the Free Software Foundation, either version 3 of the
77+# License, or (at your option) any later version.
78+#
79+# This program is distributed in the hope that it will be useful,
80+# but WITHOUT ANY WARRANTY; without even the implied warranty of
81+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82+# GNU Affero General Public License for more details.
83+#
84+# You should have received a copy of the GNU Affero General Public License
85+# along with this program. If not, see <http://www.gnu.org/licenses/>.
86+#
87+##############################################################################
88+
89+from openerp.osv import orm
90+from openerp.tools import ustr
91+
92+
93+class AccountBankStatement(orm.Model):
94+ _inherit = 'account.bank.statement'
95+
96+ def get_tax_move_lines(
97+ self, cr, uid, st_line, defaults,
98+ company_currency_id, context=None):
99+ """
100+ Process inclusive taxes on bank statement lines.
101+
102+ @param st_line: browse record of the statement line
103+ @param defaults: dictionary of default move line values. Usually
104+ the same as the originating move line.
105+
106+ return one or more serialized tax move lines and a set of values to
107+ update the originating move line with, containing the new amount.
108+ """
109+
110+ if not st_line.tax_id:
111+ return False, False
112+ tax_obj = self.pool.get('account.tax')
113+ move_lines = []
114+ update_move_line = {}
115+ base_amount = -defaults['credit'] or defaults['debit']
116+ tax_obj = self.pool.get('account.tax')
117+
118+ fiscal_position = (
119+ st_line.partner_id.property_account_position
120+ if st_line.partner_id and
121+ st_line.partner_id.property_account_position
122+ else False)
123+ tax_ids = self.pool.get('account.fiscal.position').map_tax(
124+ cr, uid, fiscal_position, [st_line.tax_id])
125+ taxes = tax_obj.browse(cr, uid, tax_ids, context=context)
126+
127+ computed_taxes = tax_obj.compute_all(
128+ cr, uid, taxes, base_amount, 1.00)
129+
130+ for tax in computed_taxes['taxes']:
131+ if tax['tax_code_id']:
132+ if not update_move_line.get('tax_code_id'):
133+ update_move_line['tax_code_id'] = tax['base_code_id']
134+ update_move_line['tax_amount'] = tax['base_sign'] * (
135+ computed_taxes.get('total', 0.0))
136+ # As the tax is inclusive, we need to correct the amount on the
137+ # original move line
138+ amount = computed_taxes.get('total', 0.0)
139+ update_move_line['credit'] = ((amount < 0) and -amount) or 0.0
140+ update_move_line['debit'] = ((amount > 0) and amount) or 0.0
141+
142+ move_lines.append({
143+ 'move_id': defaults['move_id'],
144+ 'name': defaults.get('name', '') + ' ' + ustr(tax['name'] or ''),
145+ 'date': defaults.get('date', False),
146+ 'partner_id': defaults.get('partner_id', False),
147+ 'ref': defaults.get('ref', False),
148+ 'statement_id': defaults.get('statement_id'),
149+ 'tax_code_id': tax['tax_code_id'],
150+ 'tax_amount': tax['tax_sign'] * tax.get('amount', 0.0),
151+ 'account_id': tax.get('account_collected_id', defaults['account_id']),
152+ 'credit': tax['amount'] < 0 and - tax['amount'] or 0.0,
153+ 'debit': tax['amount'] > 0 and tax['amount'] or 0.0,
154+ 'account_id': tax.get('account_collected_id', defaults['account_id']),
155+ })
156+
157+ return move_lines, update_move_line
158+
159+ def _prepare_bank_move_line(
160+ self, cr, uid, st_line, move_id, amount, company_currency_id,
161+ context=None):
162+ """
163+ Overload of the original method from the account module. Create
164+ the tax move lines.
165+ """
166+ res = super(AccountBankStatement, self)._prepare_bank_move_line(
167+ cr, uid, st_line, move_id, amount, company_currency_id,
168+ context=context)
169+ if st_line.tax_id:
170+ tax_move_lines, counterpart_update_vals = self.get_tax_move_lines(
171+ cr, uid, st_line, res, company_currency_id, context=context)
172+ res.update(counterpart_update_vals)
173+ for tax_move_line in tax_move_lines:
174+ self.pool.get('account.move.line').create(
175+ cr, uid, tax_move_line, context=context)
176+ return res
177
178=== added file 'account_bank_statement_tax/model/account_bank_statement_line.py'
179--- account_bank_statement_tax/model/account_bank_statement_line.py 1970-01-01 00:00:00 +0000
180+++ account_bank_statement_tax/model/account_bank_statement_line.py 2013-10-06 19:03:39 +0000
181@@ -0,0 +1,34 @@
182+# -*- coding: utf-8 -*-
183+##############################################################################
184+#
185+# Copyright (C) 2012 - 2013 Therp BV (<http://therp.nl>).
186+# All Rights Reserved
187+#
188+# This program is free software: you can redistribute it and/or modify
189+# it under the terms of the GNU Affero General Public License as
190+# published by the Free Software Foundation, either version 3 of the
191+# License, or (at your option) any later version.
192+#
193+# This program is distributed in the hope that it will be useful,
194+# but WITHOUT ANY WARRANTY; without even the implied warranty of
195+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
196+# GNU Affero General Public License for more details.
197+#
198+# You should have received a copy of the GNU Affero General Public License
199+# along with this program. If not, see <http://www.gnu.org/licenses/>.
200+#
201+##############################################################################
202+
203+from openerp.osv import orm, fields
204+
205+
206+class AccountBankStatementLine(orm.Model):
207+ _inherit = 'account.bank.statement.line'
208+
209+ _columns = {
210+ 'tax_id': fields.many2one(
211+ 'account.tax', 'Tax',
212+ domain=[('price_include','=', True)],
213+ help="Apply an (inclusive) tax from the bank statement line",
214+ ),
215+ }
216
217=== added directory 'account_bank_statement_tax/view'
218=== added file 'account_bank_statement_tax/view/account_bank_statement.xml'
219--- account_bank_statement_tax/view/account_bank_statement.xml 1970-01-01 00:00:00 +0000
220+++ account_bank_statement_tax/view/account_bank_statement.xml 2013-10-06 19:03:39 +0000
221@@ -0,0 +1,18 @@
222+<?xml version="1.0" encoding="utf-8"?>
223+<openerp>
224+ <data>
225+ <record id="view_bank_statement_form" model="ir.ui.view">
226+ <field name="name">Add tax to the embedded bank statement line form</field>
227+ <field name="inherit_id" ref="account.view_bank_statement_form" />
228+ <field name="model">account.bank.statement</field>
229+ <field name="arch" type="xml">
230+ <xpath expr="//field[@name='line_ids']/tree/field[@name='amount']"
231+ position="after">
232+ <field name="tax_id"
233+ domain="[('parent_id', '=', False), ('price_include', '=', True), ('type_tax_use', 'in', (amount and amount &gt; 0 and ('sale', 'all') or ('purchase', 'all')))]"
234+ />
235+ </xpath>
236+ </field>
237+ </record>
238+ </data>
239+</openerp>

Subscribers

People subscribed via source and target branches

to status/vote changes: