Merge lp:~florian-dacosta/banking-addons/bank-statement-reconcile-7.0-one-move_with_transfer_lines into lp:~akretion-team/banking-addons/bank-statement-reconcile-7.0-one-move

Proposed by Florian da Costa
Status: Merged
Merged at revision: 112
Proposed branch: lp:~florian-dacosta/banking-addons/bank-statement-reconcile-7.0-one-move_with_transfer_lines
Merge into: lp:~akretion-team/banking-addons/bank-statement-reconcile-7.0-one-move
Diff against target: 111 lines (+72/-1) (has conflicts)
2 files modified
account_statement_one_move/statement.py (+71/-1)
account_statement_one_move/statement_view.xml (+1/-0)
Text conflict in account_statement_one_move/statement.py
To merge this branch: bzr merge lp:~florian-dacosta/banking-addons/bank-statement-reconcile-7.0-one-move_with_transfer_lines
Reviewer Review Type Date Requested Status
Sébastien BEAU - http://www.akretion.com Pending
Review via email: mp+201779@code.launchpad.net

Description of the change

When confirming a bank statement, if the one move option is checked in the profile, it will generated one or two transfer lines.
The option split_transfer_line (in profile) will create a refund transfer line and a payment transfer line.
If the option is not checked, then only one global transfer line will be generated.

To post a comment you must log in.
110. By Florian da Costa

[FIX] Automatically create transfer move lines instead of bank statement transfer lines

111. By Florian da Costa

[FIX] simplify code

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_statement_one_move/statement.py'
2--- account_statement_one_move/statement.py 2014-01-31 21:03:42 +0000
3+++ account_statement_one_move/statement.py 2014-02-07 12:46:48 +0000
4@@ -30,7 +30,15 @@
5 'Group Journal Items',
6 help="Only one Journal Entry will be generated on the "
7 "validation of the bank statement."),
8- }
9+<<<<<<< TREE
10+ }
11+=======
12+ 'split_transfer_line': fields.boolean(
13+ 'Split Transfer Line',
14+ help="Two transfer lines will be automatically generated : one "
15+ "for the refunds and one for the payments.")
16+ }
17+>>>>>>> MERGE-SOURCE
18
19 class account_bank_statement(orm.Model):
20 _inherit = "account.bank.statement"
21@@ -124,9 +132,69 @@
22 move_obj.post(cr, uid, [move_id], context=context)
23 return True
24
25+
26+ def _prepare_transfer_move_line_vals(self, cr, uid, st, name, amount, move_id, context=None):
27+ """
28+ Prepare the dict of values to create the transfer move lines.
29+ """
30+ account_id = st.profile_id.journal_id.default_debit_account_id.id
31+ partner_id = st.profile_id.partner_id and profile.partner_id.id or False
32+ if amount < 0.0:
33+ debit = 0.0
34+ credit = -amount
35+ else:
36+ debit = amount
37+ credit = 0.0
38+ vals = {
39+ 'name': name,
40+ 'date': st.date,
41+ 'partner_id': partner_id,
42+ 'statement_id': st.id,
43+ 'account_id': account_id,
44+ 'ref': name,
45+ 'move_id': move_id,
46+ 'credit': credit,
47+ 'debit': debit,
48+ 'journal_id': st.journal_id.id,
49+ 'period_id': st.period_id.id,
50+ }
51+ return vals
52+
53+
54+ def create_move_transfer_lines(self, cr, uid, move, st, context=None):
55+ move_line_obj = self.pool.get('account.move.line')
56+ move_id = move.id
57+ refund = 0.0
58+ payment = 0.0
59+ transfer_lines = []
60+ transfer_line_ids = []
61+ #Calculate the part of the refund amount and the payment amount
62+ for move_line in move.line_id:
63+ refund -= move_line.debit
64+ payment += move_line.credit
65+ #Create 2 Transfer lines or One global tranfer line
66+ if st.profile_id.split_transfer_line:
67+ if refund:
68+ transfer_lines.append(['Refund Transfer', refund])
69+ if payment:
70+ transfer_lines.append(['Payment Transfer', payment])
71+ else:
72+ amount = payment + refund
73+ if amount:
74+ transfer_lines.append(['Transfer', amount])
75+ for transfer_line in transfer_lines:
76+ vals = self._prepare_transfer_move_line_vals(cr, uid, st,
77+ transfer_line[0],
78+ transfer_line[1],
79+ move_id,
80+ context=context)
81+ transfer_line_ids.append(move_line_obj.create(cr, uid, vals, context=context))
82+ return transfer_line_ids
83+
84
85 def button_confirm_bank(self, cr, uid, ids, context=None):
86 st_line_obj = self.pool.get('account.bank.statement.line')
87+ move_obj = self.pool.get('account.move')
88 if context is None:
89 context = {}
90 for st in self.browse(cr, uid, ids, context=context):
91@@ -134,6 +202,8 @@
92 context=context)
93 if st.profile_id.one_move and context.get('move_id', False):
94 move_id = context['move_id']
95+ move = move_obj.browse(cr, uid, move_id, context=context)
96+ transfe_line_ids = self.create_move_transfer_lines(cr, uid, move, st, context=context)
97 self._valid_move(cr, uid, move_id, context=context)
98 lines_ids = [x.id for x in st.line_ids]
99 st_line_obj.write(cr, uid, lines_ids,
100
101=== modified file 'account_statement_one_move/statement_view.xml'
102--- account_statement_one_move/statement_view.xml 2014-01-15 13:46:57 +0000
103+++ account_statement_one_move/statement_view.xml 2014-02-07 12:46:48 +0000
104@@ -17,6 +17,7 @@
105 <field name="arch" type="xml">
106 <field name="balance_check" position="after">
107 <field name="one_move"/>
108+ <field name="split_transfer_line" attrs="{'invisible': [('one_move', '=', False)]}"/>
109 </field>
110 </field>
111 </record>

Subscribers

People subscribed via source and target branches