From 5e0f9f6b6a4d358c1474422ec423d0949964cb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Beau?= Date: Thu, 11 Jul 2013 02:45:16 +0200 Subject: [PATCH 01/12] [ADD] add module account_statement_one_move --- account_statement_one_move/__init__.py | 24 ++ account_statement_one_move/__openerp__.py | 39 +++ account_statement_one_move/statement.py | 234 ++++++++++++++++++ account_statement_one_move/statement_view.xml | 27 ++ 4 files changed, 324 insertions(+) create mode 100644 account_statement_one_move/__init__.py create mode 100644 account_statement_one_move/__openerp__.py create mode 100644 account_statement_one_move/statement.py create mode 100644 account_statement_one_move/statement_view.xml diff --git a/account_statement_one_move/__init__.py b/account_statement_one_move/__init__.py new file mode 100644 index 00000000..bf2e6751 --- /dev/null +++ b/account_statement_one_move/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# account_statement_one_move for OpenERP +# Copyright (C) 2013-TODAY Akretion . +# @author Sébastien BEAU +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +import statement + diff --git a/account_statement_one_move/__openerp__.py b/account_statement_one_move/__openerp__.py new file mode 100644 index 00000000..19a8b1f5 --- /dev/null +++ b/account_statement_one_move/__openerp__.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# account_statement_one_move for OpenERP +# Copyright (C) 2013-TODAY Akretion . +# @author Sébastien BEAU +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +{ + 'name': 'account_statement_one_move', + 'version': '0.1', + 'category': 'Generic Modules/Others', + 'license': 'AGPL-3', + 'description': """empty""", + 'author': 'Akretion', + 'website': 'http://www.akretion.com/', + 'depends': ['account_statement_ext'], + 'init_xml': [], + 'update_xml': [ + 'statement_view.xml' + ], + 'demo_xml': [], + 'installable': True, + 'active': False, +} diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py new file mode 100644 index 00000000..a36a790b --- /dev/null +++ b/account_statement_one_move/statement.py @@ -0,0 +1,234 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# account_statement_one_move for OpenERP +# Copyright (C) 2013-TODAY Akretion . +# @author Sébastien BEAU +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +from openerp.osv import fields, orm, osv + + + +class AccountStatementProfil(orm.Model): + _inherit = "account.statement.profile" + _columns = { + 'one_move': fields.boolean('One Move', + help="Tic that box if you want OpenERP to generated only" + "one move when the bank statement is validated") + } + + +class account_bank_statement(orm.Model): + _inherit = "account.bank.statement" + + ##################### START UGLY COPY/PASTE + #REALLY SORRY for the ugly code but the module bank statement should be re-written + #It is impossible to overwrite it correctly + def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None): + """ + Override a large portion of the code to compute the periode for each line instead of + taking the period of the whole statement. + Remove the entry posting on generated account moves. + We change the move line generated from the lines depending on the profile: + - If receivable_account_id is set, we'll use it instead of the "partner" one + - If partner_id is set, we'll us it for the commission (when imported throufh the wizard) + - If partner_id is set and force_partner_on_bank is ticked, we'll let the partner of each line + for the debit line, but we'll change it on the credit move line for the choosen partner_id + => This will ease the reconciliation process with the bank as the partner will match the bank + statement line + + :param int/long: st_line_id: account.bank.statement.line ID + :param int/long: company_currency_id: res.currency ID + :param char: st_line_number: that will be used as the name of the generated account move + :return: int/long: ID of the created account.move + """ + if context is None: + context = {} + res_currency_obj = self.pool.get('res.currency') + account_move_obj = self.pool.get('account.move') + account_move_line_obj = self.pool.get('account.move.line') + account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') # Chg + st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context=context) # Chg + st = st_line.statement_id + + context.update({'date': st_line.date}) + ctx = context.copy() # Chg + ctx['company_id'] = st_line.company_id.id # Chg + period_id = self._get_period( # Chg + cr, uid, st_line.date, context=ctx) + + if context.get('move_id'): #Chg2 + move_id = context['move_id'] #Chg2 + else: #Chg2 + move_id = account_move_obj.create(cr, uid, { + 'journal_id': st.journal_id.id, + 'period_id': period_id, # Chg + 'date': st_line.date, + 'name': st_line_number, + 'ref': st_line.ref, + }, context=context) + account_bank_statement_line_obj.write(cr, uid, [st_line.id], { # Chg + 'move_ids': [(4, move_id, False)] + }) + + torec = [] + if st_line.amount >= 0: + account_id = st.journal_id.default_credit_account_id.id + else: + account_id = st.journal_id.default_debit_account_id.id + + acc_cur = ((st_line.amount<=0) and st.journal_id.default_debit_account_id) or st_line.account_id + context.update({ + 'res.currency.compute.account': acc_cur, + }) + amount = res_currency_obj.compute(cr, uid, st.currency.id, + company_currency_id, st_line.amount, context=context) + + val = { + 'name': st_line.name, + 'date': st_line.date, + 'ref': st_line.ref, + 'move_id': move_id, + 'partner_id': ((st_line.partner_id) and st_line.partner_id.id) or False, + 'account_id': (st_line.account_id) and st_line.account_id.id, + 'credit': ((amount>0) and amount) or 0.0, + 'debit': ((amount<0) and -amount) or 0.0, + # Replace with the treasury one instead of bank #Chg + 'statement_id': st.id, + 'journal_id': st.journal_id.id, + 'period_id': period_id, #Chg + 'currency_id': st.currency.id, + 'analytic_account_id': st_line.analytic_account_id and st_line.analytic_account_id.id or False + } + + if st.currency.id <> company_currency_id: + amount_cur = res_currency_obj.compute(cr, uid, company_currency_id, + st.currency.id, amount, context=context) + val['amount_currency'] = -amount_cur + + if st_line.account_id and st_line.account_id.currency_id and st_line.account_id.currency_id.id <> company_currency_id: + val['currency_id'] = st_line.account_id.currency_id.id + amount_cur = res_currency_obj.compute(cr, uid, company_currency_id, + st_line.account_id.currency_id.id, amount, context=context) + val['amount_currency'] = -amount_cur + + move_line_id = account_move_line_obj.create(cr, uid, val, context=context) + torec.append(move_line_id) + + if context['move_id']: #Chg2 + return move_id #Chg2 + + # Fill the secondary amount/currency + # if currency is not the same than the company + amount_currency = False + currency_id = False + if st.currency.id <> company_currency_id: + amount_currency = st_line.amount + currency_id = st.currency.id + # GET THE RIGHT PARTNER ACCORDING TO THE CHOSEN PROFIL # Chg + if st.profile_id.force_partner_on_bank: # Chg + bank_parrtner_id = st.profile_id.partner_id.id # Chg + else: # Chg + bank_parrtner_id = ((st_line.partner_id) and st_line.partner_id.id) or False # Chg + + account_move_line_obj.create(cr, uid, { + 'name': st_line.name, + 'date': st_line.date, + 'ref': st_line.ref, + 'move_id': move_id, + 'partner_id': bank_parrtner_id, # Chg + 'account_id': account_id, + 'credit': ((amount < 0) and -amount) or 0.0, + 'debit': ((amount > 0) and amount) or 0.0, + # Replace with the treasury one instead of bank #Chg + 'statement_id': st.id, + 'journal_id': st.journal_id.id, + 'period_id': period_id, #Chg + 'amount_currency': amount_currency, + 'currency_id': currency_id, + }, context=context) + + for line in account_move_line_obj.browse(cr, uid, [x.id for x in + account_move_obj.browse(cr, uid, move_id, + context=context).line_id], + context=context): + if line.state <> 'valid': + raise osv.except_osv(_('Error !'), + _('Journal item "%s" is not valid.') % line.name) + + # Bank statements will not consider boolean on journal entry_posted + account_move_obj.post(cr, uid, [move_id], context=context) + return move_id + + + + ####################### END OF UGLY COPY/PASTE + + def _prepare_move(self, cr, uid, st, context=None): + period_id = st.period_id or self._get_period( + cr, uid, st.date, context=context) + return { + 'journal_id': st.journal_id.id, + 'period_id': period_id, + 'date': st.date, + 'name': st.name, + 'ref': st.name, + } + + def _create_move(self, cr, uid, st, context=None): + move_obj = self.pool.get('account.move') + move_vals = self._prepare_move(cr, uid, st, context=context) + return move_obj.create(cr, uid, move_vals, context=context) + + def _valid_move(self, cr, uid, move_id, context=None): + move_obj = self.pool.get('account.move') + move = move_obj.browse(cr, uid, move_id, context=context) + move_obj.post(cr, uid, [move_id], context=context) + return True + + def button_confirm_bank(self, cr, uid, ids, context=None): + st_line_obj = self.pool.get('account.bank.statement.line') + if context is None: + context = {} + for st in self.browse(cr, uid, ids, context=context): + if st.profile_id.one_move: + move_id = self._create_move(cr, uid, st, context=context) + context['move_id'] = move_id + super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, context=context) + if st.profile_id.one_move: + self._valid_move(cr, uid, move_id, context=context) + lines_ids = [x.id for x in st.line_ids] + st_line_obj.write(cr, uid, lines_ids, + {'move_ids': [(4, move_id, False)]}, + context=context) + return True + + def button_cancel(self, cr, uid, ids, context=None): + done = [] + for st in self.browse(cr, uid, ids, context=context): + if st.profile_id.one_move: + for move in st.line_ids[0].move_ids: + if move.state <> 'draft': + move.button_cancel(context=context) + move.unlink(context=context) + st.write({'state':'draft'}, context=context) + else: + super(account_bank_statement, self).button_cancel(cr, uid, ids, context=context) + return True + + diff --git a/account_statement_one_move/statement_view.xml b/account_statement_one_move/statement_view.xml new file mode 100644 index 00000000..3fb1d23d --- /dev/null +++ b/account_statement_one_move/statement_view.xml @@ -0,0 +1,27 @@ + + + + + + + + + + account_statement_one_move.account_statement.view_form + account.statement.profile + + + form + + + + + + + + + From d9aaf1656f3405a9f63aa06c652bb72ba9e4d1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Beau?= Date: Tue, 23 Jul 2013 00:49:38 +0200 Subject: [PATCH 02/12] [FIX] fix intentation error, and fill the move_line name with the line reference of the bank statement --- account_statement_one_move/statement.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index a36a790b..5d7613fb 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -116,6 +116,11 @@ class account_bank_statement(orm.Model): 'analytic_account_id': st_line.analytic_account_id and st_line.analytic_account_id.id or False } + #We use the reference as name as in case of one move #Chg2 + #as field ref is a related we had the same value for all move #Chg2 + if context.get('move_id'): #Chg2 + val['name'] = st_line.ref #Chg2 + if st.currency.id <> company_currency_id: amount_cur = res_currency_obj.compute(cr, uid, company_currency_id, st.currency.id, amount, context=context) @@ -130,7 +135,7 @@ class account_bank_statement(orm.Model): move_line_id = account_move_line_obj.create(cr, uid, val, context=context) torec.append(move_line_id) - if context['move_id']: #Chg2 + if context.get('move_id'): #Chg2 return move_id #Chg2 # Fill the secondary amount/currency @@ -229,6 +234,6 @@ class account_bank_statement(orm.Model): st.write({'state':'draft'}, context=context) else: super(account_bank_statement, self).button_cancel(cr, uid, ids, context=context) - return True + return True From 5daaab672332480a1f3dcc827565ab539d627c96 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Sun, 3 Nov 2013 15:37:31 +0100 Subject: [PATCH 03/12] [IMP] port module account_statement_one_move on V7 --- account_statement_one_move/statement.py | 192 +++++------------------- 1 file changed, 40 insertions(+), 152 deletions(-) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index 5d7613fb..e27c2f20 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -36,171 +36,61 @@ class AccountStatementProfil(orm.Model): class account_bank_statement(orm.Model): _inherit = "account.bank.statement" - ##################### START UGLY COPY/PASTE - #REALLY SORRY for the ugly code but the module bank statement should be re-written - #It is impossible to overwrite it correctly - def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None): - """ - Override a large portion of the code to compute the periode for each line instead of - taking the period of the whole statement. - Remove the entry posting on generated account moves. - We change the move line generated from the lines depending on the profile: - - If receivable_account_id is set, we'll use it instead of the "partner" one - - If partner_id is set, we'll us it for the commission (when imported throufh the wizard) - - If partner_id is set and force_partner_on_bank is ticked, we'll let the partner of each line - for the debit line, but we'll change it on the credit move line for the choosen partner_id - => This will ease the reconciliation process with the bank as the partner will match the bank - statement line - - :param int/long: st_line_id: account.bank.statement.line ID - :param int/long: company_currency_id: res.currency ID - :param char: st_line_number: that will be used as the name of the generated account move - :return: int/long: ID of the created account.move + def _prepare_move_line_vals(self, cr, uid, st_line, *args, **kwargs): + res = super(account_bank_statement, self)._prepare_move_line_vals(cr, uid, st_line, *args, **kwargs) + if st_line.statement_id.profile_id.one_move: + res.update({ + 'date': st_line.statement_id.date, + 'name': st_line.ref, + }) + return res + + def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context): + account_move_obj = self.pool.get('account.move') + account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') + st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context=context) + st = st_line.statement_id + + if st.profile_id.one_move: + if not context.get('move_id'): + move_vals = self._prepare_move(cr, uid, st_line, st_line_number, context=context) + context['move_id'] = account_move_obj.create(cr, uid, move_vals, context=context) + self.create_move_line_from_st_line(cr, uid, context['move_id'], st_line_id, company_currency_id, context=context) + return context['move_id'] + else: + return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line_id, company_currency_id, st_line_number, context=context) + + def create_move_line_from_st_line(self, cr, uid, move_id, st_line_id, company_currency_id, context): + """Create the account move line from the statement line. + + :param int/long move_id: ID of the account.move + :param int/long st_line_id: ID of the account.bank.statement.line to create the move line from. + :param int/long company_currency_id: ID of the res.currency of the company + :return: ID of the account.move created """ + if context is None: context = {} res_currency_obj = self.pool.get('res.currency') - account_move_obj = self.pool.get('account.move') account_move_line_obj = self.pool.get('account.move.line') - account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') # Chg - st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context=context) # Chg + account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') + st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context=context) st = st_line.statement_id context.update({'date': st_line.date}) - ctx = context.copy() # Chg - ctx['company_id'] = st_line.company_id.id # Chg - period_id = self._get_period( # Chg - cr, uid, st_line.date, context=ctx) - - if context.get('move_id'): #Chg2 - move_id = context['move_id'] #Chg2 - else: #Chg2 - move_id = account_move_obj.create(cr, uid, { - 'journal_id': st.journal_id.id, - 'period_id': period_id, # Chg - 'date': st_line.date, - 'name': st_line_number, - 'ref': st_line.ref, - }, context=context) - account_bank_statement_line_obj.write(cr, uid, [st_line.id], { # Chg - 'move_ids': [(4, move_id, False)] - }) - - torec = [] - if st_line.amount >= 0: - account_id = st.journal_id.default_credit_account_id.id - else: - account_id = st.journal_id.default_debit_account_id.id - acc_cur = ((st_line.amount<=0) and st.journal_id.default_debit_account_id) or st_line.account_id + context.update({ 'res.currency.compute.account': acc_cur, }) amount = res_currency_obj.compute(cr, uid, st.currency.id, company_currency_id, st_line.amount, context=context) - val = { - 'name': st_line.name, - 'date': st_line.date, - 'ref': st_line.ref, - 'move_id': move_id, - 'partner_id': ((st_line.partner_id) and st_line.partner_id.id) or False, - 'account_id': (st_line.account_id) and st_line.account_id.id, - 'credit': ((amount>0) and amount) or 0.0, - 'debit': ((amount<0) and -amount) or 0.0, - # Replace with the treasury one instead of bank #Chg - 'statement_id': st.id, - 'journal_id': st.journal_id.id, - 'period_id': period_id, #Chg - 'currency_id': st.currency.id, - 'analytic_account_id': st_line.analytic_account_id and st_line.analytic_account_id.id or False - } + bank_move_vals = self._prepare_bank_move_line(cr, uid, st_line, move_id, amount, + company_currency_id, context=context) + return account_move_line_obj.create(cr, uid, bank_move_vals, context=context) - #We use the reference as name as in case of one move #Chg2 - #as field ref is a related we had the same value for all move #Chg2 - if context.get('move_id'): #Chg2 - val['name'] = st_line.ref #Chg2 - - if st.currency.id <> company_currency_id: - amount_cur = res_currency_obj.compute(cr, uid, company_currency_id, - st.currency.id, amount, context=context) - val['amount_currency'] = -amount_cur - - if st_line.account_id and st_line.account_id.currency_id and st_line.account_id.currency_id.id <> company_currency_id: - val['currency_id'] = st_line.account_id.currency_id.id - amount_cur = res_currency_obj.compute(cr, uid, company_currency_id, - st_line.account_id.currency_id.id, amount, context=context) - val['amount_currency'] = -amount_cur - - move_line_id = account_move_line_obj.create(cr, uid, val, context=context) - torec.append(move_line_id) - - if context.get('move_id'): #Chg2 - return move_id #Chg2 - - # Fill the secondary amount/currency - # if currency is not the same than the company - amount_currency = False - currency_id = False - if st.currency.id <> company_currency_id: - amount_currency = st_line.amount - currency_id = st.currency.id - # GET THE RIGHT PARTNER ACCORDING TO THE CHOSEN PROFIL # Chg - if st.profile_id.force_partner_on_bank: # Chg - bank_parrtner_id = st.profile_id.partner_id.id # Chg - else: # Chg - bank_parrtner_id = ((st_line.partner_id) and st_line.partner_id.id) or False # Chg - - account_move_line_obj.create(cr, uid, { - 'name': st_line.name, - 'date': st_line.date, - 'ref': st_line.ref, - 'move_id': move_id, - 'partner_id': bank_parrtner_id, # Chg - 'account_id': account_id, - 'credit': ((amount < 0) and -amount) or 0.0, - 'debit': ((amount > 0) and amount) or 0.0, - # Replace with the treasury one instead of bank #Chg - 'statement_id': st.id, - 'journal_id': st.journal_id.id, - 'period_id': period_id, #Chg - 'amount_currency': amount_currency, - 'currency_id': currency_id, - }, context=context) - - for line in account_move_line_obj.browse(cr, uid, [x.id for x in - account_move_obj.browse(cr, uid, move_id, - context=context).line_id], - context=context): - if line.state <> 'valid': - raise osv.except_osv(_('Error !'), - _('Journal item "%s" is not valid.') % line.name) - - # Bank statements will not consider boolean on journal entry_posted - account_move_obj.post(cr, uid, [move_id], context=context) - return move_id - - - - ####################### END OF UGLY COPY/PASTE - - def _prepare_move(self, cr, uid, st, context=None): - period_id = st.period_id or self._get_period( - cr, uid, st.date, context=context) - return { - 'journal_id': st.journal_id.id, - 'period_id': period_id, - 'date': st.date, - 'name': st.name, - 'ref': st.name, - } - - def _create_move(self, cr, uid, st, context=None): - move_obj = self.pool.get('account.move') - move_vals = self._prepare_move(cr, uid, st, context=context) - return move_obj.create(cr, uid, move_vals, context=context) - - def _valid_move(self, cr, uid, move_id, context=None): + def _valid_move(self, cr, uid, move_id, context=None): move_obj = self.pool.get('account.move') move = move_obj.browse(cr, uid, move_id, context=context) move_obj.post(cr, uid, [move_id], context=context) @@ -211,11 +101,9 @@ class account_bank_statement(orm.Model): if context is None: context = {} for st in self.browse(cr, uid, ids, context=context): - if st.profile_id.one_move: - move_id = self._create_move(cr, uid, st, context=context) - context['move_id'] = move_id super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, context=context) if st.profile_id.one_move: + move_id = context['move_id'] self._valid_move(cr, uid, move_id, context=context) lines_ids = [x.id for x in st.line_ids] st_line_obj.write(cr, uid, lines_ids, From f622212dbec02ddd10cd7f90b345e9b16a740830 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Mon, 18 Nov 2013 12:19:02 +0100 Subject: [PATCH 04/12] [FIX] fix period id on move line --- account_statement_one_move/statement.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index e27c2f20..41706d72 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -38,13 +38,28 @@ class account_bank_statement(orm.Model): def _prepare_move_line_vals(self, cr, uid, st_line, *args, **kwargs): res = super(account_bank_statement, self)._prepare_move_line_vals(cr, uid, st_line, *args, **kwargs) + period_id = self._get_period(cr, uid, st_line.statement_id.date, context=kwargs.get('context')) if st_line.statement_id.profile_id.one_move: res.update({ + 'period_id': period_id, 'date': st_line.statement_id.date, 'name': st_line.ref, }) return res + + return res + + def _prepare_move(self, cr, uid, st_line, st_line_number, context=None): + res = super(account_bank_statement, self).\ + _prepare_move(cr, uid, st_line, st_line_number, context=context) + res.update({ + 'ref': st_line.statement_id.name, + 'name': st_line.statement_id.name, + 'date': st_line.statement_id.date, + }) + return res + def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context): account_move_obj = self.pool.get('account.move') account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') @@ -68,7 +83,6 @@ class account_bank_statement(orm.Model): :param int/long company_currency_id: ID of the res.currency of the company :return: ID of the account.move created """ - if context is None: context = {} res_currency_obj = self.pool.get('res.currency') @@ -90,7 +104,7 @@ class account_bank_statement(orm.Model): company_currency_id, context=context) return account_move_line_obj.create(cr, uid, bank_move_vals, context=context) - def _valid_move(self, cr, uid, move_id, context=None): + def _valid_move(self, cr, uid, move_id, context=None): move_obj = self.pool.get('account.move') move = move_obj.browse(cr, uid, move_id, context=context) move_obj.post(cr, uid, [move_id], context=context) From ac625c78e9bf3a763495f63eee281f0a12d9e1b9 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Thu, 12 Dec 2013 22:38:08 +0100 Subject: [PATCH 05/12] [FIX] Fix some code length, fill description, change module name --- account_statement_one_move/__openerp__.py | 15 +++++++---- account_statement_one_move/statement.py | 32 ++++++++++++++++------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/account_statement_one_move/__openerp__.py b/account_statement_one_move/__openerp__.py index 19a8b1f5..5ddb0cc3 100644 --- a/account_statement_one_move/__openerp__.py +++ b/account_statement_one_move/__openerp__.py @@ -21,19 +21,24 @@ ############################################################################### { - 'name': 'account_statement_one_move', + 'name': 'Bank statement one move', 'version': '0.1', 'category': 'Generic Modules/Others', 'license': 'AGPL-3', - 'description': """empty""", + 'description': """ + This module allow to groupe all lines of a bank statement in only one move. This feature is optional + and can be activated with a checkbox in the bank statement's profile. This is very useful for credit card deposit for example, + you won't have a move for each line. + + """, 'author': 'Akretion', 'website': 'http://www.akretion.com/', 'depends': ['account_statement_ext'], - 'init_xml': [], - 'update_xml': [ + 'data': [ 'statement_view.xml' ], - 'demo_xml': [], + 'demo': [], 'installable': True, + 'auto_install': False, 'active': False, } diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index 41706d72..e473e01f 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -37,8 +37,10 @@ class account_bank_statement(orm.Model): _inherit = "account.bank.statement" def _prepare_move_line_vals(self, cr, uid, st_line, *args, **kwargs): - res = super(account_bank_statement, self)._prepare_move_line_vals(cr, uid, st_line, *args, **kwargs) - period_id = self._get_period(cr, uid, st_line.statement_id.date, context=kwargs.get('context')) + res = super(account_bank_statement, self)._prepare_move_line_vals(cr, uid, st_line, + *args, **kwargs) + period_id = self._get_period(cr, uid, st_line.statement_id.date, + context=kwargs.get('context')) if st_line.statement_id.profile_id.one_move: res.update({ 'period_id': period_id, @@ -60,22 +62,32 @@ class account_bank_statement(orm.Model): }) return res - def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context): + def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, + st_line_number, context=None): + if context is None: + context = {} account_move_obj = self.pool.get('account.move') account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') - st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context=context) + st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, + context=context) st = st_line.statement_id if st.profile_id.one_move: if not context.get('move_id'): move_vals = self._prepare_move(cr, uid, st_line, st_line_number, context=context) context['move_id'] = account_move_obj.create(cr, uid, move_vals, context=context) - self.create_move_line_from_st_line(cr, uid, context['move_id'], st_line_id, company_currency_id, context=context) + self.create_move_line_from_st_line(cr, uid, context['move_id'], + st_line_id, company_currency_id, + context=context) return context['move_id'] else: - return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line_id, company_currency_id, st_line_number, context=context) + return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line_id, + company_currency_id, + st_line_number, + context=context) - def create_move_line_from_st_line(self, cr, uid, move_id, st_line_id, company_currency_id, context): + def create_move_line_from_st_line(self, cr, uid, move_id, st_line_id, + company_currency_id, context=None): """Create the account move line from the statement line. :param int/long move_id: ID of the account.move @@ -115,7 +127,8 @@ class account_bank_statement(orm.Model): if context is None: context = {} for st in self.browse(cr, uid, ids, context=context): - super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, context=context) + super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, + context=context) if st.profile_id.one_move: move_id = context['move_id'] self._valid_move(cr, uid, move_id, context=context) @@ -135,7 +148,8 @@ class account_bank_statement(orm.Model): move.unlink(context=context) st.write({'state':'draft'}, context=context) else: - super(account_bank_statement, self).button_cancel(cr, uid, ids, context=context) + super(account_bank_statement, self).button_cancel(cr, uid, ids, + context=context) return True From 0d262e8890708f1100b44a73753ca6e5e33df808 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 15 Jan 2014 14:46:57 +0100 Subject: [PATCH 06/12] [FIX] Minor fixes --- account_statement_one_move/__init__.py | 3 +-- account_statement_one_move/__openerp__.py | 2 +- account_statement_one_move/statement.py | 20 +++++++++++-------- account_statement_one_move/statement_view.xml | 2 -- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/account_statement_one_move/__init__.py b/account_statement_one_move/__init__.py index bf2e6751..141c95fc 100644 --- a/account_statement_one_move/__init__.py +++ b/account_statement_one_move/__init__.py @@ -20,5 +20,4 @@ # ############################################################################### -import statement - +from . import statement diff --git a/account_statement_one_move/__openerp__.py b/account_statement_one_move/__openerp__.py index 5ddb0cc3..266c6ce7 100644 --- a/account_statement_one_move/__openerp__.py +++ b/account_statement_one_move/__openerp__.py @@ -26,7 +26,7 @@ 'category': 'Generic Modules/Others', 'license': 'AGPL-3', 'description': """ - This module allow to groupe all lines of a bank statement in only one move. This feature is optional + This module allows to group all lines of a bank statement in only one move. This feature is optional and can be activated with a checkbox in the bank statement's profile. This is very useful for credit card deposit for example, you won't have a move for each line. diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index e473e01f..ef6d0f21 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -23,14 +23,13 @@ from openerp.osv import fields, orm, osv - -class AccountStatementProfil(orm.Model): +class AccountStatementProfile(orm.Model): _inherit = "account.statement.profile" _columns = { - 'one_move': fields.boolean('One Move', - help="Tic that box if you want OpenERP to generated only" - "one move when the bank statement is validated") - } + 'one_move': fields.boolean( + 'Group Journal Items', + help="Only one Journal Entry will be generated on the " + "validation of the bank statement."), class account_bank_statement(orm.Model): @@ -62,6 +61,7 @@ class account_bank_statement(orm.Model): }) return res + def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None): if context is None: @@ -110,7 +110,9 @@ class account_bank_statement(orm.Model): 'res.currency.compute.account': acc_cur, }) amount = res_currency_obj.compute(cr, uid, st.currency.id, - company_currency_id, st_line.amount, context=context) + company_currency_id, + st_line.amount, + context=context) bank_move_vals = self._prepare_bank_move_line(cr, uid, st_line, move_id, amount, company_currency_id, context=context) @@ -122,6 +124,7 @@ class account_bank_statement(orm.Model): move_obj.post(cr, uid, [move_id], context=context) return True + def button_confirm_bank(self, cr, uid, ids, context=None): st_line_obj = self.pool.get('account.bank.statement.line') if context is None: @@ -142,8 +145,9 @@ class account_bank_statement(orm.Model): done = [] for st in self.browse(cr, uid, ids, context=context): if st.profile_id.one_move: + assert st.line_ids, "This statement does not contain any lines" for move in st.line_ids[0].move_ids: - if move.state <> 'draft': + if move.state != 'draft': move.button_cancel(context=context) move.unlink(context=context) st.write({'state':'draft'}, context=context) diff --git a/account_statement_one_move/statement_view.xml b/account_statement_one_move/statement_view.xml index 3fb1d23d..8a145f22 100644 --- a/account_statement_one_move/statement_view.xml +++ b/account_statement_one_move/statement_view.xml @@ -14,8 +14,6 @@ account_statement_one_move.account_statement.view_form account.statement.profile - - form From e071aad62e541e816203dfc80ff0770dd4e6804c Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 15 Jan 2014 14:58:05 +0100 Subject: [PATCH 07/12] [IMP] Add transfer lines automatically to balance the bank statement --- account_statement_one_move/statement.py | 83 ++++++++++++++++++- account_statement_one_move/statement_view.xml | 1 + 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index ef6d0f21..1616fe4a 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -21,6 +21,8 @@ ############################################################################### from openerp.osv import fields, orm, osv +from openerp.tools.translate import _ + class AccountStatementProfile(orm.Model): @@ -30,6 +32,11 @@ class AccountStatementProfile(orm.Model): 'Group Journal Items', help="Only one Journal Entry will be generated on the " "validation of the bank statement."), + 'split_transfer_line': fields.boolean( + 'Split Transfer Line', + help="Two transfer lines will be automatically generated : one " + "for the refunds and one for the payments.") + } class account_bank_statement(orm.Model): @@ -124,12 +131,86 @@ class account_bank_statement(orm.Model): move_obj.post(cr, uid, [move_id], context=context) return True - + + def create_statement_payment_line(self, cr, uid, st, payment_amount, context=None): + st_line_obj = self.pool.get('account.bank.statement.line') + payment_account_id = st.profile_id.journal_id.default_credit_account_id.id + partner_id = st.profile_id.partner_id and profile.partner_id.id or False + vals = { + 'name': _('Payment Transfer'), + 'date': st.date, + 'amount': -payment_amount, + 'partner_id': partner_id, + 'type': 'general', + 'statement_id': st.id, + 'account_id': payment_account_id, + 'ref': _('Transfer'), + 'already_completed': True + } + payment_line_id = st_line_obj.create(cr, uid, vals, context=context) + return payment_line_id + + + def create_statement_refund_line(self, cr, uid, st, refund_amount, context=None): + st_line_obj = self.pool.get('account.bank.statement.line') + refund_account_id = st.profile_id.journal_id.default_credit_account_id.id + partner_id = st.profile_id.partner_id and profile.partner_id.id or False + vals = { + 'name': _('Refund Transfer'), + 'date': st.date, + 'amount': -refund_amount, + 'partner_id': partner_id, + 'type': 'general', + 'statement_id': st.id, + 'account_id': refund_account_id, + 'ref': _('Transfer'), + 'already_completed': True + } + refund_line_id = st_line_obj.create(cr, uid, vals, context=context) + return refund_line_id + + + def prepare_statement_transfer_lines(self, cr, uid, st, context=None): + refund_amount = 0.0 + payment_amount = 0.0 + transfer_line_ids = [] + #Calculate the part of the refund amount and the payment amount + for st_line in st.line_ids: + if st_line.amount < 0.0: + refund_amount += st_line.amount + else: + payment_amount += st_line.amount + #Create 2 Transfer lines or One global tranfer line + if st.profile_id.split_transfer_line: + transfer_line_ids.append(self.create_statement_refund_line(cr, uid, st, + refund_amount, + context=context)) + transfer_line_ids.append(self.create_statement_payment_line(cr, uid, st, + payment_amount, + context=context)) + else: + global_amount = refund_amount + payment_amount + #The global transfer line can be a refund or a payment transfer + if global_amount < 0.00: + transfer_line_ids.append(self.create_statement_refund_line(cr, uid, st, + global_amount, + context=context)) + else: + transfer_line_ids.append(self.create_statement_payment_line(cr, uid, st, + global_amount, + context=context)) + return transfer_line_ids + + + def button_confirm_bank(self, cr, uid, ids, context=None): st_line_obj = self.pool.get('account.bank.statement.line') if context is None: context = {} for st in self.browse(cr, uid, ids, context=context): + if st.profile_id.one_move: + refund_line_ids = self.prepare_statement_transfer_lines(cr, uid, st, + context=context) super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, context=context) if st.profile_id.one_move: diff --git a/account_statement_one_move/statement_view.xml b/account_statement_one_move/statement_view.xml index 8a145f22..e0e19fc8 100644 --- a/account_statement_one_move/statement_view.xml +++ b/account_statement_one_move/statement_view.xml @@ -17,6 +17,7 @@ + From 07e41d89150e536ea503ae8a73a287b5be24ac59 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 31 Jan 2014 20:52:16 +0100 Subject: [PATCH 08/12] [FIX] Automatically create transfer move lines instead of bank statement transfer lines --- account_statement_one_move/statement.py | 110 +++++++++++------------- 1 file changed, 48 insertions(+), 62 deletions(-) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index 1616fe4a..af4c3d03 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -21,8 +21,6 @@ ############################################################################### from openerp.osv import fields, orm, osv -from openerp.tools.translate import _ - class AccountStatementProfile(orm.Model): @@ -38,7 +36,6 @@ class AccountStatementProfile(orm.Model): "for the refunds and one for the payments.") } - class account_bank_statement(orm.Model): _inherit = "account.bank.statement" @@ -132,89 +129,78 @@ class account_bank_statement(orm.Model): return True - def create_statement_payment_line(self, cr, uid, st, payment_amount, context=None): - st_line_obj = self.pool.get('account.bank.statement.line') - payment_account_id = st.profile_id.journal_id.default_credit_account_id.id + def _prepare_transfer_move_line_vals(self, cr, uid, st, name, debit, credit, move_id, context=None): + """ + Prepare the dict of values to create the transfer move lines. + """ + account_id = st.profile_id.journal_id.default_debit_account_id.id partner_id = st.profile_id.partner_id and profile.partner_id.id or False vals = { - 'name': _('Payment Transfer'), + 'name': name, 'date': st.date, - 'amount': -payment_amount, 'partner_id': partner_id, - 'type': 'general', 'statement_id': st.id, - 'account_id': payment_account_id, - 'ref': _('Transfer'), - 'already_completed': True - } - payment_line_id = st_line_obj.create(cr, uid, vals, context=context) - return payment_line_id + 'account_id': account_id, + 'ref': name, + 'move_id': move_id, + 'credit': credit, + 'debit': debit, + 'journal_id': st.journal_id.id, + 'period_id': st.period_id.id, + } + return vals - def create_statement_refund_line(self, cr, uid, st, refund_amount, context=None): - st_line_obj = self.pool.get('account.bank.statement.line') - refund_account_id = st.profile_id.journal_id.default_credit_account_id.id - partner_id = st.profile_id.partner_id and profile.partner_id.id or False - vals = { - 'name': _('Refund Transfer'), - 'date': st.date, - 'amount': -refund_amount, - 'partner_id': partner_id, - 'type': 'general', - 'statement_id': st.id, - 'account_id': refund_account_id, - 'ref': _('Transfer'), - 'already_completed': True - } - refund_line_id = st_line_obj.create(cr, uid, vals, context=context) - return refund_line_id - - - def prepare_statement_transfer_lines(self, cr, uid, st, context=None): - refund_amount = 0.0 - payment_amount = 0.0 + def create_move_transfer_lines(self, cr, uid, move, st, context=None): + move_line_obj = self.pool.get('account.move.line') + move_id = move.id + refund = 0.0 + payment = 0.0 transfer_line_ids = [] #Calculate the part of the refund amount and the payment amount - for st_line in st.line_ids: - if st_line.amount < 0.0: - refund_amount += st_line.amount - else: - payment_amount += st_line.amount + for move_line in move.line_id: + refund += move_line.debit + payment += move_line.credit #Create 2 Transfer lines or One global tranfer line - if st.profile_id.split_transfer_line: - transfer_line_ids.append(self.create_statement_refund_line(cr, uid, st, - refund_amount, - context=context)) - transfer_line_ids.append(self.create_statement_payment_line(cr, uid, st, - payment_amount, - context=context)) + refund_name = 'Refund Transfer' + payment_name = 'Payment Transfer' + if st.profile_id.split_transfer_line and refund != 0.0 and payment != 0.0: + refund_vals = self._prepare_transfer_move_line_vals(cr, uid, st, + refund_name, 0, refund, + move_id, context=context) + transfer_line_ids.append(move_line_obj.create(cr, uid, refund_vals, context=context)) + payment_vals = self._prepare_transfer_move_line_vals(cr, uid, st, + payment_name, payment, 0, + move_id, context=context) + transfer_line_ids.append(move_line_obj.create(cr, uid, payment_vals, context=context)) else: - global_amount = refund_amount + payment_amount #The global transfer line can be a refund or a payment transfer - if global_amount < 0.00: - transfer_line_ids.append(self.create_statement_refund_line(cr, uid, st, - global_amount, - context=context)) + global_amount = abs(payment-refund) + if payment > refund: + vals = self._prepare_transfer_move_line_vals(cr, uid, st, + payment_name, + global_amount, 0, + move_id, context=context) else: - transfer_line_ids.append(self.create_statement_payment_line(cr, uid, st, - global_amount, - context=context)) + vals = self._prepare_transfer_move_line_vals(cr, uid, st, + refund_name, 0, global_amount, + move_id, context=context) + transfer_line_ids.append(move_line_obj.create(cr, uid, vals, context=context)) return transfer_line_ids - - + def button_confirm_bank(self, cr, uid, ids, context=None): st_line_obj = self.pool.get('account.bank.statement.line') + move_obj = self.pool.get('account.move') if context is None: context = {} for st in self.browse(cr, uid, ids, context=context): - if st.profile_id.one_move: - refund_line_ids = self.prepare_statement_transfer_lines(cr, uid, st, - context=context) super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, context=context) if st.profile_id.one_move: move_id = context['move_id'] + move = move_obj.browse(cr, uid, move_id, context=context) + transfe_line_ids = self.create_move_transfer_lines(cr, uid, move, st, context=context) self._valid_move(cr, uid, move_id, context=context) lines_ids = [x.id for x in st.line_ids] st_line_obj.write(cr, uid, lines_ids, From 342afc6445f03193250ee3a26d1ef1dda03f6afb Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 31 Jan 2014 21:56:30 +0100 Subject: [PATCH 09/12] [FIX] replace assert by a simple check in cancel method + add a check on the context in the button_confirm_bank method --- account_statement_one_move/statement.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index ef6d0f21..9951abb7 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -132,7 +132,7 @@ class account_bank_statement(orm.Model): for st in self.browse(cr, uid, ids, context=context): super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, context=context) - if st.profile_id.one_move: + if st.profile_id.one_move and context.get('move_id', False): move_id = context['move_id'] self._valid_move(cr, uid, move_id, context=context) lines_ids = [x.id for x in st.line_ids] @@ -144,8 +144,7 @@ class account_bank_statement(orm.Model): def button_cancel(self, cr, uid, ids, context=None): done = [] for st in self.browse(cr, uid, ids, context=context): - if st.profile_id.one_move: - assert st.line_ids, "This statement does not contain any lines" + if st.profile_id.one_move and st.line_ids: for move in st.line_ids[0].move_ids: if move.state != 'draft': move.button_cancel(context=context) From 6835d74e34f8421b8fde60dd9ef72c704cb12fb7 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 31 Jan 2014 22:03:42 +0100 Subject: [PATCH 10/12] [FIX] add closing bracket --- account_statement_one_move/statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index 9951abb7..5abf78c4 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -30,7 +30,7 @@ class AccountStatementProfile(orm.Model): 'Group Journal Items', help="Only one Journal Entry will be generated on the " "validation of the bank statement."), - + } class account_bank_statement(orm.Model): _inherit = "account.bank.statement" From b83af513536181d2a233ba0a410420e4d605c928 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 7 Feb 2014 13:45:52 +0100 Subject: [PATCH 11/12] [FIX] simplify code --- account_statement_one_move/statement.py | 47 ++++++++++++------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index af4c3d03..687fcbf7 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -129,12 +129,18 @@ class account_bank_statement(orm.Model): return True - def _prepare_transfer_move_line_vals(self, cr, uid, st, name, debit, credit, move_id, context=None): + def _prepare_transfer_move_line_vals(self, cr, uid, st, name, amount, move_id, context=None): """ Prepare the dict of values to create the transfer move lines. """ account_id = st.profile_id.journal_id.default_debit_account_id.id partner_id = st.profile_id.partner_id and profile.partner_id.id or False + if amount < 0.0: + debit = 0.0 + credit = -amount + else: + debit = amount + credit = 0.0 vals = { 'name': name, 'date': st.date, @@ -156,35 +162,28 @@ class account_bank_statement(orm.Model): move_id = move.id refund = 0.0 payment = 0.0 + transfer_lines = [] transfer_line_ids = [] #Calculate the part of the refund amount and the payment amount for move_line in move.line_id: - refund += move_line.debit + refund -= move_line.debit payment += move_line.credit #Create 2 Transfer lines or One global tranfer line - refund_name = 'Refund Transfer' - payment_name = 'Payment Transfer' - if st.profile_id.split_transfer_line and refund != 0.0 and payment != 0.0: - refund_vals = self._prepare_transfer_move_line_vals(cr, uid, st, - refund_name, 0, refund, - move_id, context=context) - transfer_line_ids.append(move_line_obj.create(cr, uid, refund_vals, context=context)) - payment_vals = self._prepare_transfer_move_line_vals(cr, uid, st, - payment_name, payment, 0, - move_id, context=context) - transfer_line_ids.append(move_line_obj.create(cr, uid, payment_vals, context=context)) + if st.profile_id.split_transfer_line: + if refund: + transfer_lines.append(['Refund Transfer', refund]) + if payment: + transfer_lines.append(['Payment Transfer', payment]) else: - #The global transfer line can be a refund or a payment transfer - global_amount = abs(payment-refund) - if payment > refund: - vals = self._prepare_transfer_move_line_vals(cr, uid, st, - payment_name, - global_amount, 0, - move_id, context=context) - else: - vals = self._prepare_transfer_move_line_vals(cr, uid, st, - refund_name, 0, global_amount, - move_id, context=context) + amount = payment + refund + if amount: + transfer_lines.append(['Transfer', amount]) + for transfer_line in transfer_lines: + vals = self._prepare_transfer_move_line_vals(cr, uid, st, + transfer_line[0], + transfer_line[1], + move_id, + context=context) transfer_line_ids.append(move_line_obj.create(cr, uid, vals, context=context)) return transfer_line_ids From 44b598805ee3c33d0de3cefffb5ea05a183f15c0 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 7 Feb 2014 13:48:29 +0100 Subject: [PATCH 12/12] [FIX] Fix compability with account_constraints --- account_statement_one_move/statement.py | 1 + 1 file changed, 1 insertion(+) diff --git a/account_statement_one_move/statement.py b/account_statement_one_move/statement.py index 5abf78c4..6540358d 100644 --- a/account_statement_one_move/statement.py +++ b/account_statement_one_move/statement.py @@ -66,6 +66,7 @@ class account_bank_statement(orm.Model): st_line_number, context=None): if context is None: context = {} + context['from_parent_object'] = True #For compability with module account_constraints account_move_obj = self.pool.get('account.move') account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id,