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
=== added directory 'account_bank_statement_tax'
=== added file 'account_bank_statement_tax/__init__.py'
--- account_bank_statement_tax/__init__.py 1970-01-01 00:00:00 +0000
+++ account_bank_statement_tax/__init__.py 2013-10-06 19:03:39 +0000
@@ -0,0 +1,1 @@
1import model
02
=== added file 'account_bank_statement_tax/__openerp__.py'
--- account_bank_statement_tax/__openerp__.py 1970-01-01 00:00:00 +0000
+++ account_bank_statement_tax/__openerp__.py 2013-10-06 19:03:39 +0000
@@ -0,0 +1,43 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Copyright (C) 2012 - 2013 Therp BV (<http://therp.nl>).
5# All Rights Reserved
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': 'Apply a tax on bank statement lines',
24 'version': '0.1',
25 'license': 'AGPL-3',
26 'author': 'Therp BV',
27 'website': 'https://launchpad.net/banking-addons',
28 'category': 'Banking addons',
29 'depends': [
30 'account',
31 ],
32 'data': [
33 'view/account_bank_statement.xml',
34 ],
35 'description': '''
36Allow an (inclusive) tax to be set on a bank statement line. When the
37statement is confirmed, the tax will be processed like a tax set on a
38move line.
39
40This module is co-funded by BAS Solutions.
41 ''',
42 'installable': True,
43}
044
=== added directory 'account_bank_statement_tax/model'
=== added file 'account_bank_statement_tax/model/__init__.py'
--- account_bank_statement_tax/model/__init__.py 1970-01-01 00:00:00 +0000
+++ account_bank_statement_tax/model/__init__.py 2013-10-06 19:03:39 +0000
@@ -0,0 +1,2 @@
1import account_bank_statement_line
2import account_bank_statement
03
=== added file 'account_bank_statement_tax/model/account_bank_statement.py'
--- account_bank_statement_tax/model/account_bank_statement.py 1970-01-01 00:00:00 +0000
+++ account_bank_statement_tax/model/account_bank_statement.py 2013-10-06 19:03:39 +0000
@@ -0,0 +1,109 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Copyright (C) 2012 - 2013 Therp BV (<http://therp.nl>).
5# All Rights Reserved
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
23from openerp.tools import ustr
24
25
26class AccountBankStatement(orm.Model):
27 _inherit = 'account.bank.statement'
28
29 def get_tax_move_lines(
30 self, cr, uid, st_line, defaults,
31 company_currency_id, context=None):
32 """
33 Process inclusive taxes on bank statement lines.
34
35 @param st_line: browse record of the statement line
36 @param defaults: dictionary of default move line values. Usually
37 the same as the originating move line.
38
39 return one or more serialized tax move lines and a set of values to
40 update the originating move line with, containing the new amount.
41 """
42
43 if not st_line.tax_id:
44 return False, False
45 tax_obj = self.pool.get('account.tax')
46 move_lines = []
47 update_move_line = {}
48 base_amount = -defaults['credit'] or defaults['debit']
49 tax_obj = self.pool.get('account.tax')
50
51 fiscal_position = (
52 st_line.partner_id.property_account_position
53 if st_line.partner_id and
54 st_line.partner_id.property_account_position
55 else False)
56 tax_ids = self.pool.get('account.fiscal.position').map_tax(
57 cr, uid, fiscal_position, [st_line.tax_id])
58 taxes = tax_obj.browse(cr, uid, tax_ids, context=context)
59
60 computed_taxes = tax_obj.compute_all(
61 cr, uid, taxes, base_amount, 1.00)
62
63 for tax in computed_taxes['taxes']:
64 if tax['tax_code_id']:
65 if not update_move_line.get('tax_code_id'):
66 update_move_line['tax_code_id'] = tax['base_code_id']
67 update_move_line['tax_amount'] = tax['base_sign'] * (
68 computed_taxes.get('total', 0.0))
69 # As the tax is inclusive, we need to correct the amount on the
70 # original move line
71 amount = computed_taxes.get('total', 0.0)
72 update_move_line['credit'] = ((amount < 0) and -amount) or 0.0
73 update_move_line['debit'] = ((amount > 0) and amount) or 0.0
74
75 move_lines.append({
76 'move_id': defaults['move_id'],
77 'name': defaults.get('name', '') + ' ' + ustr(tax['name'] or ''),
78 'date': defaults.get('date', False),
79 'partner_id': defaults.get('partner_id', False),
80 'ref': defaults.get('ref', False),
81 'statement_id': defaults.get('statement_id'),
82 'tax_code_id': tax['tax_code_id'],
83 'tax_amount': tax['tax_sign'] * tax.get('amount', 0.0),
84 'account_id': tax.get('account_collected_id', defaults['account_id']),
85 'credit': tax['amount'] < 0 and - tax['amount'] or 0.0,
86 'debit': tax['amount'] > 0 and tax['amount'] or 0.0,
87 'account_id': tax.get('account_collected_id', defaults['account_id']),
88 })
89
90 return move_lines, update_move_line
91
92 def _prepare_bank_move_line(
93 self, cr, uid, st_line, move_id, amount, company_currency_id,
94 context=None):
95 """
96 Overload of the original method from the account module. Create
97 the tax move lines.
98 """
99 res = super(AccountBankStatement, self)._prepare_bank_move_line(
100 cr, uid, st_line, move_id, amount, company_currency_id,
101 context=context)
102 if st_line.tax_id:
103 tax_move_lines, counterpart_update_vals = self.get_tax_move_lines(
104 cr, uid, st_line, res, company_currency_id, context=context)
105 res.update(counterpart_update_vals)
106 for tax_move_line in tax_move_lines:
107 self.pool.get('account.move.line').create(
108 cr, uid, tax_move_line, context=context)
109 return res
0110
=== added file 'account_bank_statement_tax/model/account_bank_statement_line.py'
--- account_bank_statement_tax/model/account_bank_statement_line.py 1970-01-01 00:00:00 +0000
+++ account_bank_statement_tax/model/account_bank_statement_line.py 2013-10-06 19:03:39 +0000
@@ -0,0 +1,34 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Copyright (C) 2012 - 2013 Therp BV (<http://therp.nl>).
5# All Rights Reserved
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 AccountBankStatementLine(orm.Model):
26 _inherit = 'account.bank.statement.line'
27
28 _columns = {
29 'tax_id': fields.many2one(
30 'account.tax', 'Tax',
31 domain=[('price_include','=', True)],
32 help="Apply an (inclusive) tax from the bank statement line",
33 ),
34 }
035
=== added directory 'account_bank_statement_tax/view'
=== added file 'account_bank_statement_tax/view/account_bank_statement.xml'
--- account_bank_statement_tax/view/account_bank_statement.xml 1970-01-01 00:00:00 +0000
+++ account_bank_statement_tax/view/account_bank_statement.xml 2013-10-06 19:03:39 +0000
@@ -0,0 +1,18 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <record id="view_bank_statement_form" model="ir.ui.view">
5 <field name="name">Add tax to the embedded bank statement line form</field>
6 <field name="inherit_id" ref="account.view_bank_statement_form" />
7 <field name="model">account.bank.statement</field>
8 <field name="arch" type="xml">
9 <xpath expr="//field[@name='line_ids']/tree/field[@name='amount']"
10 position="after">
11 <field name="tax_id"
12 domain="[('parent_id', '=', False), ('price_include', '=', True), ('type_tax_use', 'in', (amount and amount &gt; 0 and ('sale', 'all') or ('purchase', 'all')))]"
13 />
14 </xpath>
15 </field>
16 </record>
17 </data>
18</openerp>

Subscribers

People subscribed via source and target branches

to status/vote changes: