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/46] [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/46] [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 1de11e7e120b6a0c965850a2963eb38b687e027a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Oct 2013 10:22:48 +0100 Subject: [PATCH 03/46] [FIX] account_statement: crash when creating a new bank statement without any lines --- account_statement_ext/statement.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index f8762054..03e1c31c 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -31,9 +31,10 @@ def fixed_write(self, cr, uid, ids, vals, context=None): I will do it when I have time.""" res = super(stat_mod.account_bank_statement, self).write(cr, uid, ids, vals, context=context) - cr.execute("UPDATE account_bank_statement_line" - " SET sequence = account_bank_statement_line.id + 1" - " where statement_id in %s", (tuple(ids),)) + if ids: # will be false for an new empty bank statement + cr.execute("UPDATE account_bank_statement_line" + " SET sequence = account_bank_statement_line.id + 1" + " where statement_id in %s", (tuple(ids),)) return res stat_mod.account_bank_statement.write = fixed_write From 572f28a20196d668d000e65cfb5ccf284bc755c0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Oct 2013 10:23:29 +0100 Subject: [PATCH 04/46] [ADD] new module makine Point Of Sale compatible with bank profiles --- .../__init__.py | 22 +++++ .../__openerp__.py | 43 +++++++++ .../point_of_sale.py | 95 +++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 account_statement_ext_point_of_sale/__init__.py create mode 100644 account_statement_ext_point_of_sale/__openerp__.py create mode 100644 account_statement_ext_point_of_sale/point_of_sale.py diff --git a/account_statement_ext_point_of_sale/__init__.py b/account_statement_ext_point_of_sale/__init__.py new file mode 100644 index 00000000..2f5d1c8e --- /dev/null +++ b/account_statement_ext_point_of_sale/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# +# 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 point_of_sale diff --git a/account_statement_ext_point_of_sale/__openerp__.py b/account_statement_ext_point_of_sale/__openerp__.py new file mode 100644 index 00000000..9e06022c --- /dev/null +++ b/account_statement_ext_point_of_sale/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Nicolas Bessi, Joel Grand-Guillaume +# Copyright 2011-2013 Camptocamp SA +# +# 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': "Bank statement extension and profiles for Point of Sale", + 'version': '1.0.0', + 'author': 'Camptocamp', + 'maintainer': 'Camptocamp', + 'category': 'Point Of Sale', + 'complexity': 'normal', + 'depends': ['point_of_sale', + 'account_statement_ext', + ], + 'description': """ + Update the point of sale code to work with improved bank statements. + """, + 'website': 'http://www.camptocamp.com', + 'data': [], + 'demo': [], + 'test': [], + 'installable': True, + 'images': [], + 'auto_install': True, + 'license': 'AGPL-3', + 'active': False, + } diff --git a/account_statement_ext_point_of_sale/point_of_sale.py b/account_statement_ext_point_of_sale/point_of_sale.py new file mode 100644 index 00000000..a765a596 --- /dev/null +++ b/account_statement_ext_point_of_sale/point_of_sale.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# +# 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.addons.point_of_sale.point_of_sale import pos_session as std_pos_session +from openerp.osv import orm, osv +from openerp.tools.translate import _ + +if not hasattr(std_pos_session, '_prepare_bank_statement'): + # monkey patch to fix lp:1245375 + def mp_prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): + bank_values = { + 'journal_id' : journal.id, + 'user_id' : uid, + 'company_id' : pos_config.shop_id.company_id.id + } + return bank_values + + def mp_create(self, cr, uid, values, context=None): + context = context or {} + config_id = values.get('config_id', False) or context.get('default_config_id', False) + if not config_id: + raise osv.except_osv( _('Error!'), + _("You should assign a Point of Sale to your session.")) + + # journal_id is not required on the pos_config because it does not + # exists at the installation. If nothing is configured at the + # installation we do the minimal configuration. Impossible to do in + # the .xml files as the CoA is not yet installed. + jobj = self.pool.get('pos.config') + pos_config = jobj.browse(cr, uid, config_id, context=context) + context.update({'company_id': pos_config.shop_id.company_id.id}) + if not pos_config.journal_id: + jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id'] + if jid: + jobj.write(cr, uid, [pos_config.id], {'journal_id': jid}, context=context) + else: + raise osv.except_osv( _('error!'), + _("Unable to open the session. You have to assign a sale journal to your point of sale.")) + + # define some cash journal if no payment method exists + if not pos_config.journal_ids: + journal_proxy = self.pool.get('account.journal') + cashids = journal_proxy.search(cr, uid, [('journal_user', '=', True), ('type','=','cash')], context=context) + if not cashids: + cashids = journal_proxy.search(cr, uid, [('type', '=', 'cash')], context=context) + if not cashids: + cashids = journal_proxy.search(cr, uid, [('journal_user','=',True)], context=context) + + jobj.write(cr, uid, [pos_config.id], {'journal_ids': [(6,0, cashids)]}) + + + pos_config = jobj.browse(cr, uid, config_id, context=context) + bank_statement_ids = [] + print pos_config.journal_ids + for journal in pos_config.journal_ids: + bank_values = self._prepare_bank_statement(cr, uid, pos_config, journal, context) + statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context) + bank_statement_ids.append(statement_id) + + values.update({ + 'name' : pos_config.sequence_id._next(), + 'statement_ids' : [(6, 0, bank_statement_ids)], + 'config_id': config_id + }) + return super(std_pos_session, self).create(cr, uid, values, context=context) + + std_pos_session._prepare_bank_statement = mp_prepare_bank_statement + std_pos_session.create = mp_create + + +class pos_session(orm.Model): + _inherit = 'pos.session' + + def _prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): + bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid, pos_config, journal, context) + defaults = self.pool['account.bank.statement'].default_get(cr, uid, ['profile_id', 'period_id'], context=context) + bank_values.update(defaults) + return bank_values From 5daaab672332480a1f3dcc827565ab539d627c96 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Sun, 3 Nov 2013 15:37:31 +0100 Subject: [PATCH 05/46] [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 1542a46695ef2efe4e8038467edd66f57df8462b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Nov 2013 16:57:28 +0100 Subject: [PATCH 06/46] [FIX] select the correct profile when creating the bank statement --- account_statement_ext_point_of_sale/point_of_sale.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/account_statement_ext_point_of_sale/point_of_sale.py b/account_statement_ext_point_of_sale/point_of_sale.py index a765a596..06384dd3 100644 --- a/account_statement_ext_point_of_sale/point_of_sale.py +++ b/account_statement_ext_point_of_sale/point_of_sale.py @@ -68,7 +68,6 @@ if not hasattr(std_pos_session, '_prepare_bank_statement'): pos_config = jobj.browse(cr, uid, config_id, context=context) bank_statement_ids = [] - print pos_config.journal_ids for journal in pos_config.journal_ids: bank_values = self._prepare_bank_statement(cr, uid, pos_config, journal, context) statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context) @@ -90,6 +89,12 @@ class pos_session(orm.Model): def _prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid, pos_config, journal, context) + user_obj = self.pool.get('res.users') + profile_obj = self.pool.get('account.statement.profile') + user = user_obj.browse(cr, uid, uid, context=context) defaults = self.pool['account.bank.statement'].default_get(cr, uid, ['profile_id', 'period_id'], context=context) + profile_ids = profile_obj.search(cr, uid, [('company_id', '=', user.company_id.id), ('journal_id', '=', bank_values['journal_id'])], context=context) + if profile_ids: + defaults['profile_id'] = profile_ids[0] bank_values.update(defaults) return bank_values From 1c4a105a5f28f734e9e76c40726aef6ccca209b0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Nov 2013 08:04:05 +0100 Subject: [PATCH 07/46] [PEP8] --- account_statement_ext_point_of_sale/__init__.py | 2 +- account_statement_ext_point_of_sale/__openerp__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/account_statement_ext_point_of_sale/__init__.py b/account_statement_ext_point_of_sale/__init__.py index 2f5d1c8e..05435f81 100644 --- a/account_statement_ext_point_of_sale/__init__.py +++ b/account_statement_ext_point_of_sale/__init__.py @@ -19,4 +19,4 @@ # ############################################################################## -import point_of_sale +from . import point_of_sale diff --git a/account_statement_ext_point_of_sale/__openerp__.py b/account_statement_ext_point_of_sale/__openerp__.py index 9e06022c..6d4b7a8f 100644 --- a/account_statement_ext_point_of_sale/__openerp__.py +++ b/account_statement_ext_point_of_sale/__openerp__.py @@ -29,7 +29,7 @@ 'account_statement_ext', ], 'description': """ - Update the point of sale code to work with improved bank statements. + Update the point of sale code to work with improved bank statements. """, 'website': 'http://www.camptocamp.com', 'data': [], From 93e04e145ab9d7f357da51b81bbc6f2c75d33d39 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Nov 2013 08:16:39 +0100 Subject: [PATCH 08/46] [IMP] explain what the monkey patching bit is about --- account_statement_ext_point_of_sale/point_of_sale.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/account_statement_ext_point_of_sale/point_of_sale.py b/account_statement_ext_point_of_sale/point_of_sale.py index 06384dd3..729a53b3 100644 --- a/account_statement_ext_point_of_sale/point_of_sale.py +++ b/account_statement_ext_point_of_sale/point_of_sale.py @@ -24,6 +24,16 @@ from openerp.tools.translate import _ if not hasattr(std_pos_session, '_prepare_bank_statement'): # monkey patch to fix lp:1245375 + # + # We replace pos_session.create with the implementation in + # mp_create below which is essentially the same, only with a call + # to self._prepare_bank_statement. + # + # The default implementation has been extracted in + # mp_prepare_bank_statement below, and can be overridden in models + # which _inherit pos.session + # + # This change has been proposed for merging to fix lp:125375 def mp_prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): bank_values = { 'journal_id' : journal.id, From 369de56d845502fd7e742d4e065452e0edee4407 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Nov 2013 08:31:36 +0100 Subject: [PATCH 09/46] [IMP][PEP8] fixed + add a doc string to explicit fact _prepare_statement does not originally exist on base model --- .../point_of_sale.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/account_statement_ext_point_of_sale/point_of_sale.py b/account_statement_ext_point_of_sale/point_of_sale.py index 729a53b3..31e23418 100644 --- a/account_statement_ext_point_of_sale/point_of_sale.py +++ b/account_statement_ext_point_of_sale/point_of_sale.py @@ -98,12 +98,25 @@ class pos_session(orm.Model): _inherit = 'pos.session' def _prepare_bank_statement(self, cr, uid, pos_config, journal, context=None): - bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid, pos_config, journal, context) + """ Override the function _mp_create. To add the bank profile to the statement + + Function That was previously added to pos.session model using monkey patching + + """ + + bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid, + pos_config, + journal, context) user_obj = self.pool.get('res.users') profile_obj = self.pool.get('account.statement.profile') user = user_obj.browse(cr, uid, uid, context=context) - defaults = self.pool['account.bank.statement'].default_get(cr, uid, ['profile_id', 'period_id'], context=context) - profile_ids = profile_obj.search(cr, uid, [('company_id', '=', user.company_id.id), ('journal_id', '=', bank_values['journal_id'])], context=context) + defaults = self.pool['account.bank.statement'].default_get(cr, uid, + ['profile_id', 'period_id'], + context=context) + profile_ids = profile_obj.search(cr, uid, + [('company_id', '=', user.company_id.id), + ('journal_id', '=', bank_values['journal_id'])], + context=context) if profile_ids: defaults['profile_id'] = profile_ids[0] bank_values.update(defaults) From f622212dbec02ddd10cd7f90b345e9b16a740830 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Mon, 18 Nov 2013 12:19:02 +0100 Subject: [PATCH 10/46] [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 b6cb19e401f9bc3256c5cc289a084ae5631a9ea0 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 14:41:23 +0100 Subject: [PATCH 11/46] [FIX] fix api and put the incorrect method in deprecated --- account_statement_base_import/statement.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 97e8e8ab..d8badee2 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -85,7 +85,12 @@ class AccountStatementProfil(Model): context=context) return True - def prepare_statetement_lines_vals( + #Deprecated remove on V8 + def prepare_statetement_lines_vals(self, *args, **kwargs): + return super(self, AccountStatementProfil).\ + prepare_statetement_lines_vals(*args, **kwargs) + + def prepare_statement_lines_vals( self, cr, uid, parser_vals, account_payable, account_receivable, statement_id, context): """ @@ -172,7 +177,7 @@ class AccountStatementProfil(Model): statement_store = [] for line in result_row_list: parser_vals = parser.get_st_line_vals(line) - values = self.prepare_statetement_lines_vals( + values = self.prepare_statement_lines_vals( cr, uid, parser_vals, account_payable, account_receivable, statement_id, context) statement_store.append(values) From 98323e23428a0543802cc216ce92787ff74675f0 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 17:10:32 +0100 Subject: [PATCH 12/46] [IMP] do not recatch error in debug mode --- account_statement_base_import/statement.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 97e8e8ab..3964d77c 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -26,6 +26,7 @@ import datetime from openerp.osv.orm import Model from openerp.osv import fields, osv from parser import new_bank_statement_parser +from openerp.tools.config import config class AccountStatementProfil(Model): @@ -211,6 +212,8 @@ class AccountStatementProfil(Model): error_type, error_value, trbk = sys.exc_info() st = "Error: %s\nDescription: %s\nTraceback:" % (error_type.__name__, error_value) st += ''.join(traceback.format_tb(trbk, 30)) + if config['debug_mode']: + raise raise osv.except_osv(_("Statement import error"), _("The statement cannot be created: %s") % st) return statement_id From 4933e28d0670572805857d8a56fcd74352740e4d Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 17:13:46 +0100 Subject: [PATCH 13/46] [REF] remove useless unlink as the raise osv will roolback the cursor --- account_statement_base_import/statement.py | 1 - 1 file changed, 1 deletion(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index d8badee2..56fad9c0 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -212,7 +212,6 @@ class AccountStatementProfil(Model): context) except Exception: - statement_obj.unlink(cr, uid, [statement_id], context=context) error_type, error_value, trbk = sys.exc_info() st = "Error: %s\nDescription: %s\nTraceback:" % (error_type.__name__, error_value) st += ''.join(traceback.format_tb(trbk, 30)) From d1e1c06364139d6c2c51563b447a93d33adc7c1f Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 17:25:04 +0100 Subject: [PATCH 14/46] [REF] rename OpenERP class AccountBankSatement into AccountBankStatement --- .../account.py | 4 ++-- account_statement_base_completion/statement.py | 2 +- account_statement_ext/statement.py | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/account_advanced_reconcile_transaction_ref/account.py b/account_advanced_reconcile_transaction_ref/account.py index 0525de31..b3e2cd24 100644 --- a/account_advanced_reconcile_transaction_ref/account.py +++ b/account_advanced_reconcile_transaction_ref/account.py @@ -30,7 +30,7 @@ class AccountMoveLine(Model): 'transaction_ref': fields.char('Transaction Ref.', size=128), } -class AccountBankSatement(Model): +class AccountBankStatement(Model): """ Inherit account.bank.statement class in order to set transaction_ref info on account.move.line """ @@ -43,7 +43,7 @@ class AccountBankSatement(Model): if context is None: context = {} - res = super(AccountBankSatement, self)._prepare_move_line_vals( + res = super(AccountBankStatement, self)._prepare_move_line_vals( cr, uid, st_line, move_id, debit, credit, currency_id=currency_id, amount_currency=amount_currency, diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 96ab741b..d9782252 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -511,7 +511,7 @@ class AccountStatementLine(orm.Model): sql_err.pgerror) -class AccountBankSatement(orm.Model): +class AccountBankStatement(orm.Model): """ We add a basic button and stuff to support the auto-completion of the bank statement once line have been imported or manually fullfill. diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index f8762054..48667715 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -113,7 +113,7 @@ class AccountStatementProfile(Model): ] -class AccountBankSatement(Model): +class AccountBankStatement(Model): """ We improve the bank statement class mostly for : - Removing the period and compute it from the date of each line. @@ -202,7 +202,7 @@ class AccountBankSatement(Model): profile_obj = self.pool.get('account.statement.profile') profile = profile_obj.browse(cr, uid, vals['profile_id'], context=context) vals['journal_id'] = profile.journal_id.id - return super(AccountBankSatement, self).create(cr, uid, vals, context=context) + return super(AccountBankStatement, self).create(cr, uid, vals, context=context) def _get_period(self, cr, uid, date, context=None): """ @@ -243,7 +243,7 @@ class AccountBankSatement(Model): """ if context is None: context = {} - res = super(AccountBankSatement, self)._prepare_move( + res = super(AccountBankStatement, self)._prepare_move( cr, uid, st_line, st_line_number, context=context) ctx = context.copy() ctx['company_id'] = st_line.company_id.id @@ -273,7 +273,7 @@ class AccountBankSatement(Model): """ if context is None: context = {} - res = super(AccountBankSatement, self)._prepare_move_line_vals( + res = super(AccountBankStatement, self)._prepare_move_line_vals( cr, uid, st_line, move_id, debit, credit, currency_id=currency_id, amount_currency=amount_currency, @@ -297,7 +297,7 @@ class AccountBankSatement(Model): create the move from. :return: int/long of the res.partner to use as counterpart """ - bank_partner_id = super(AccountBankSatement, self)._get_counter_part_partner(cr, + bank_partner_id = super(AccountBankStatement, self)._get_counter_part_partner(cr, uid, st_line, context=context) @@ -530,7 +530,7 @@ class AccountBankSatement(Model): """ st = self.browse(cr, uid, st_id, context=context) if st.balance_check: - return super(AccountBankSatement, self).balance_check( + return super(AccountBankStatement, self).balance_check( cr, uid, st_id, journal_type, context=context) else: return True @@ -555,7 +555,7 @@ class AccountBankSatement(Model): 'credit_partner_id': credit_partner_id}} -class AccountBankSatementLine(Model): +class AccountBankStatementLine(Model): """ Override to compute the period from the date of the line, add a method to retrieve the values for a line from the profile. Override the on_change method to take care of @@ -684,7 +684,7 @@ class AccountBankSatementLine(Model): Keep the same features as in standard and call super. If an account is returned, call the method to compute line values. """ - res = super(AccountBankSatementLine, self).onchange_type(cr, uid, + res = super(AccountBankStatementLine, self).onchange_type(cr, uid, line_id, partner_id, line_type, From ac625c78e9bf3a763495f63eee281f0a12d9e1b9 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Thu, 12 Dec 2013 22:38:08 +0100 Subject: [PATCH 15/46] [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 3e4eb1095838e907b8007fdace776cd63b294bea Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 24 Dec 2013 19:16:40 +0100 Subject: [PATCH 16/46] [IMP] account_statement_base_import: private method that returns import type to ease inheritance [IMP] account_statement_ofx_import: changed accordingly previous improvement --- account_statement_base_import/statement.py | 9 +++++---- account_statement_ofx_import/statement.py | 13 +------------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 97e8e8ab..e2057bc2 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -31,12 +31,13 @@ from parser import new_bank_statement_parser class AccountStatementProfil(Model): _inherit = "account.statement.profile" - def get_import_type_selection(self, cr, uid, context=None): - """ - Has to be inherited to add parser - """ + def _get_import_type_selection(self, cr, uid, context=None): + """This is the method to be inherited for adding the parser""" return [('generic_csvxls_so', 'Generic .csv/.xls based on SO Name')] + def get_import_type_selection(self, cr, uid, context=None): + return _get_import_type selection(cr, uid, context=context) + _columns = { 'launch_import_completion': fields.boolean( "Launch completion after import", diff --git a/account_statement_ofx_import/statement.py b/account_statement_ofx_import/statement.py index c5b06fe8..bc31980a 100644 --- a/account_statement_ofx_import/statement.py +++ b/account_statement_ofx_import/statement.py @@ -24,7 +24,7 @@ from openerp.osv import fields, orm class AccountStatementProfil(orm.Model): _inherit = "account.statement.profile" - def get_import_type_selection(self, cr, uid, context=None): + def _get_import_type_selection(self, cr, uid, context=None): """ Inherited from parent to add parser. """ @@ -33,14 +33,3 @@ class AccountStatementProfil(orm.Model): context=context) selection.append(('ofx_so', _('OFX - Open Financial Exchange'))) return selection - - _columns = { - 'import_type': fields.selection( - get_import_type_selection, - 'Type of import', - required=True, - help="Choose here the method by which you want to import bank" - "statement for this profile."), - - } - From 0d262e8890708f1100b44a73753ca6e5e33df808 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 15 Jan 2014 14:46:57 +0100 Subject: [PATCH 17/46] [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 18/46] [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 df53643070492311431acea67fbcc4ba7bc7955b Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Jan 2014 14:20:56 +0100 Subject: [PATCH 19/46] Only commercial partners are allowed in bank statement lines --- account_statement_ext/statement.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 80edbfcc..2ca8627b 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -655,6 +655,8 @@ class AccountBankSatementLine(Model): # This can be quite a performance killer as we read ir.properity fields if partner_id: part = obj_partner.browse(cr, uid, partner_id, context=context) + part = part.commercial_partner_id + res['partner_id'] = part.id pay_account = part.property_account_payable.id receiv_account = part.property_account_receivable.id # If no value, look on the default company property From fda091b8d4d4892266c14cbd49886b47b37c65e4 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Jan 2014 15:10:42 +0100 Subject: [PATCH 20/46] explain the last change --- account_statement_ext/statement.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 2ca8627b..0a436ab2 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -656,6 +656,9 @@ class AccountBankSatementLine(Model): if partner_id: part = obj_partner.browse(cr, uid, partner_id, context=context) part = part.commercial_partner_id + # When the method is called from bank statement completion, + # ensure that the line's partner is a commercial + # (accounting) entity res['partner_id'] = part.id pay_account = part.property_account_payable.id receiv_account = part.property_account_receivable.id From f424f470b46c2f5de0164b11f8cadb29a67c80cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 19 Jan 2014 18:37:09 +0100 Subject: [PATCH 21/46] [IMP] pep8 + cleanup --- .../__openerp__.py | 15 +++++++-------- account_statement_bankaccount_completion/data.xml | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/account_statement_bankaccount_completion/__openerp__.py b/account_statement_bankaccount_completion/__openerp__.py index 0986b97d..e74f2ba7 100644 --- a/account_statement_bankaccount_completion/__openerp__.py +++ b/account_statement_bankaccount_completion/__openerp__.py @@ -29,21 +29,20 @@ 'account_statement_base_completion', ], 'description': """ - Add a completion method based on the partner bank account number provided by the bank/office. + Add a completion method based on the partner bank account number + provided by the bank/office. - Completion will look in the partner with that bank account number to match the partner, - then it will fill in the bank statement line with it to ease the reconciliation. + Completion will look in the partner with that bank account number + to match the partner, then it will fill in the bank statement line + with it to ease the reconciliation. """, 'website': 'http://www.acsone.eu', - 'init_xml': [], - 'update_xml': [ + 'data': [ "data.xml", ], - 'demo_xml': [], - 'test': [], + 'demo': [], 'installable': True, - 'images': [], 'auto_install': True, 'license': 'AGPL-3', } diff --git a/account_statement_bankaccount_completion/data.xml b/account_statement_bankaccount_completion/data.xml index a6a84429..685c4008 100644 --- a/account_statement_bankaccount_completion/data.xml +++ b/account_statement_bankaccount_completion/data.xml @@ -3,7 +3,7 @@ - Match from bank account number (Nomal or IBAN)) + Match from bank account number (Normal or IBAN)) 10 get_from_bank_account From 9eaf6c4109e81090cfe2c87a43b6219f51db7d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 19 Jan 2014 18:38:47 +0100 Subject: [PATCH 22/46] [FIX] account_statement_bankaccount_completion should not auto install --- account_statement_bankaccount_completion/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_bankaccount_completion/__openerp__.py b/account_statement_bankaccount_completion/__openerp__.py index e74f2ba7..d115274b 100644 --- a/account_statement_bankaccount_completion/__openerp__.py +++ b/account_statement_bankaccount_completion/__openerp__.py @@ -43,6 +43,6 @@ ], 'demo': [], 'installable': True, - 'auto_install': True, + 'auto_install': False, 'license': 'AGPL-3', } From 3f1999ed8cea4d6ba273d486e8414f23dd2971df Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 21 Jan 2014 02:04:59 +0100 Subject: [PATCH 23/46] [IMP] account_statement_base_import: Inheritable method with public name. --- account_statement_base_import/statement.py | 9 ++++----- account_statement_ofx_import/statement.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index e2057bc2..3dbddd60 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -31,12 +31,12 @@ from parser import new_bank_statement_parser class AccountStatementProfil(Model): _inherit = "account.statement.profile" - def _get_import_type_selection(self, cr, uid, context=None): + def get_import_type_selection(self, cr, uid, context=None): """This is the method to be inherited for adding the parser""" return [('generic_csvxls_so', 'Generic .csv/.xls based on SO Name')] - def get_import_type_selection(self, cr, uid, context=None): - return _get_import_type selection(cr, uid, context=context) + def _get_import_type_selection(self, cr, uid, context=None): + return get_import_type selection(cr, uid, context=context) _columns = { 'launch_import_completion': fields.boolean( @@ -47,12 +47,11 @@ class AccountStatementProfil(Model): # we remove deprecated as it floods logs in standard/warning level sob... 'rec_log': fields.text('log', readonly=True), # Deprecated 'import_type': fields.selection( - get_import_type_selection, + _get_import_type_selection, 'Type of import', required=True, help="Choose here the method by which you want to import bank" "statement for this profile."), - } def _write_extra_statement_lines( diff --git a/account_statement_ofx_import/statement.py b/account_statement_ofx_import/statement.py index bc31980a..15060360 100644 --- a/account_statement_ofx_import/statement.py +++ b/account_statement_ofx_import/statement.py @@ -24,7 +24,7 @@ from openerp.osv import fields, orm class AccountStatementProfil(orm.Model): _inherit = "account.statement.profile" - def _get_import_type_selection(self, cr, uid, context=None): + def get_import_type_selection(self, cr, uid, context=None): """ Inherited from parent to add parser. """ From 07e41d89150e536ea503ae8a73a287b5be24ac59 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 31 Jan 2014 20:52:16 +0100 Subject: [PATCH 24/46] [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 25/46] [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 26/46] [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 0f7fa422b458800dd1b9d035d7232ffaf8dd28da Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Mon, 3 Feb 2014 10:16:01 +0100 Subject: [PATCH 27/46] [FIX] Clean data --- account_statement_base_import/statement.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 56fad9c0..e85b7c8e 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -87,8 +87,7 @@ class AccountStatementProfil(Model): #Deprecated remove on V8 def prepare_statetement_lines_vals(self, *args, **kwargs): - return super(self, AccountStatementProfil).\ - prepare_statetement_lines_vals(*args, **kwargs) + return self.prepare_statement_lines_vals(*args, **kwargs) def prepare_statement_lines_vals( self, cr, uid, parser_vals, account_payable, account_receivable, From b83af513536181d2a233ba0a410420e4d605c928 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 7 Feb 2014 13:45:52 +0100 Subject: [PATCH 28/46] [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 29/46] [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, From 3278d9990e8976c6657a19d0adb4e5fd7830364d Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 12 Feb 2014 15:50:40 +0100 Subject: [PATCH 30/46] [IMP] Allow to import xlsx files --- .../parser/file_parser.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/account_statement_base_import/parser/file_parser.py b/account_statement_base_import/parser/file_parser.py index 2f4fbdaf..125605f2 100644 --- a/account_statement_base_import/parser/file_parser.py +++ b/account_statement_base_import/parser/file_parser.py @@ -35,24 +35,24 @@ def float_or_zero(val): class FileParser(BankStatementImportParser): """ - Generic abstract class for defining parser for .csv or .xls file format. + Generic abstract class for defining parser for .csv, .xls or .xlsx file format. """ def __init__(self, parse_name, ftype='csv', extra_fields=None, header=None, **kwargs): """ :param char: parse_name: The name of the parser - :param char: ftype: extension of the file (could be csv or xls) + :param char: ftype: extension of the file (could be csv, xls or xlsx) :param dict: extra_fields: extra fields to add to the conversion dict. In the format {fieldname: fieldtype} :param list: header : specify header fields if the csv file has no header """ super(FileParser, self).__init__(parse_name, **kwargs) - if ftype in ('csv', 'xls'): - self.ftype = ftype + if ftype in ('csv', 'xls' ,'xlsx'): + self.ftype = ftype[0:3] else: raise except_osv(_('User Error'), - _('Invalid file type %s. Please use csv or xls') % ftype) + _('Invalid file type %s. Please use csv, xls or xlsx') % ftype) self.conversion_dict = { 'ref': unicode, 'label': unicode, @@ -81,7 +81,7 @@ class FileParser(BankStatementImportParser): def _parse(self, *args, **kwargs): """ - Launch the parsing through .csv or .xls depending on the + Launch the parsing through .csv, .xls or .xlsx depending on the given ftype """ @@ -128,7 +128,7 @@ class FileParser(BankStatementImportParser): def _parse_xls(self): """ - :return: dict of dict from xls file (line/rows) + :return: dict of dict from xls/xlsx file (line/rows) """ wb_file = tempfile.NamedTemporaryFile() wb_file.write(self.filebuffer) @@ -180,7 +180,7 @@ class FileParser(BankStatementImportParser): def _from_xls(self, result_set, conversion_rules): """ Handle the converstion from the dict and handle date format from - an .xls file. + an .csv, .xls or .xlsx file. """ for line in result_set: for rule in conversion_rules: From bb06a4b2aa53b92252a95f8cad9f9476b913fd33 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Sun, 16 Feb 2014 16:21:52 +0100 Subject: [PATCH 31/46] [FIX] search for name in the statement line label and no vice versa --- account_statement_base_completion/statement.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 0ab8e854..b4c717e8 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -319,7 +319,9 @@ class AccountStatementCompletionRule(orm.Model): if not context['partner_memoizer']: return res st_obj = self.pool.get('account.bank.statement.line') - sql = "SELECT id FROM res_partner WHERE name ~* %s and id in %s" + sql = """SELECT id FROM ( + SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner) AS res_patner_matcher + WHERE name_match IS NOT NULL AND id IN %s """ pattern = ".*%s.*" % re.escape(st_line['name']) cr.execute(sql, (pattern, context['partner_memoizer'])) result = cr.fetchall() @@ -332,7 +334,7 @@ class AccountStatementCompletionRule(orm.Model): res['partner_id'] = result[0][0] st_vals = st_obj.get_values_for_line(cr, uid, - profile_id=st_line['porfile_id'], + profile_id=st_line['profile_id'], master_account_id=st_line['master_account_id'], partner_id=res['partner_id'], line_type=False, From 4e538950d71f31dc9a32d465a3424e5a0d2a3cba Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Sun, 16 Feb 2014 16:28:57 +0100 Subject: [PATCH 32/46] typo --- account_statement_base_completion/statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index b4c717e8..6c44517a 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -320,7 +320,7 @@ class AccountStatementCompletionRule(orm.Model): return res st_obj = self.pool.get('account.bank.statement.line') sql = """SELECT id FROM ( - SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner) AS res_patner_matcher + SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner) AS res_patner_matcher WHERE name_match IS NOT NULL AND id IN %s """ pattern = ".*%s.*" % re.escape(st_line['name']) cr.execute(sql, (pattern, context['partner_memoizer'])) From a440f845b93ff9a7caed9b629f6d50b89edb6dcf Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Sun, 16 Feb 2014 16:45:03 +0100 Subject: [PATCH 33/46] [FIX] lp:1280822 define a default value for import_type to avoid breaking tests of completions addons --- account_statement_base_import/statement.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 8da3c7b3..93b4997a 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -54,6 +54,10 @@ class AccountStatementProfil(Model): } + _defaults = { + 'import_type': 'generic_csvxls_so' + } + def _write_extra_statement_lines( self, cr, uid, parser, result_row_list, profile, statement_id, context): """Insert extra lines after the main statement lines. From b290110758141639990b800dd20b69a24d05f458 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Sun, 16 Feb 2014 19:41:04 +0100 Subject: [PATCH 34/46] a little query optimization --- account_statement_base_completion/statement.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 6c44517a..965d977e 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -320,8 +320,9 @@ class AccountStatementCompletionRule(orm.Model): return res st_obj = self.pool.get('account.bank.statement.line') sql = """SELECT id FROM ( - SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner) AS res_patner_matcher - WHERE name_match IS NOT NULL AND id IN %s """ + SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner + WHERE id IN %s) AS res_patner_matcher + WHERE name_match IS NOT NULL""" pattern = ".*%s.*" % re.escape(st_line['name']) cr.execute(sql, (pattern, context['partner_memoizer'])) result = cr.fetchall() From 4f19caeb2009f9df6bc5a9f01fd590729bcb7eea Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Mon, 17 Feb 2014 18:24:03 +0100 Subject: [PATCH 35/46] [FIX] escape res_partner.name column as second arg of regexp_matches and keep the first one as unescaped. Add a lot of tests for completion based on the res_partner name --- account_statement_base_completion/__init__.py | 4 +- .../statement.py | 6 +- .../tests/__init__.py | 27 ++++++ .../tests/test_base_completion.py | 95 +++++++++++++++++++ 4 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 account_statement_base_completion/tests/__init__.py create mode 100644 account_statement_base_completion/tests/test_base_completion.py diff --git a/account_statement_base_completion/__init__.py b/account_statement_base_completion/__init__.py index 6c9ef1bc..a219be6a 100644 --- a/account_statement_base_completion/__init__.py +++ b/account_statement_base_completion/__init__.py @@ -19,5 +19,5 @@ # ############################################################################## -import statement -import partner +from . import partner +from . import statement diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 965d977e..910234d9 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -319,12 +319,12 @@ class AccountStatementCompletionRule(orm.Model): if not context['partner_memoizer']: return res st_obj = self.pool.get('account.bank.statement.line') + # regexp_replace(name,'([^a-zA-Z0-9 -])', '\\\1', 'g'), 'i') escape the column name to avoid false positive. (ex 'jho..doe' -> 'joh\.\.doe' sql = """SELECT id FROM ( - SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner + SELECT id, regexp_matches(%s, regexp_replace(name,'([^[:alpha:]0-9 -])', %s, 'g'), 'i') AS name_match FROM res_partner WHERE id IN %s) AS res_patner_matcher WHERE name_match IS NOT NULL""" - pattern = ".*%s.*" % re.escape(st_line['name']) - cr.execute(sql, (pattern, context['partner_memoizer'])) + cr.execute(sql, (st_line['name'], r"\\\1", context['partner_memoizer'])) result = cr.fetchall() if not result: return res diff --git a/account_statement_base_completion/tests/__init__.py b/account_statement_base_completion/tests/__init__.py new file mode 100644 index 00000000..6f9e09ea --- /dev/null +++ b/account_statement_base_completion/tests/__init__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Laurent Mignon +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# 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 . import test_base_completion + +checks = [ + test_base_completion +] diff --git a/account_statement_base_completion/tests/test_base_completion.py b/account_statement_base_completion/tests/test_base_completion.py new file mode 100644 index 00000000..d9416eff --- /dev/null +++ b/account_statement_base_completion/tests/test_base_completion.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Laurent Mignon +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# 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.tests import common +import time +from collections import namedtuple + +name_completion_case = namedtuple("name_completion_case", ["partner_name", "line_label", "should_match"]) +NAMES_COMPLETION_CASES = [ + name_completion_case("Acsone", "Line for Acsone SA", True), + name_completion_case("Acsone", "Line for Acsone", True), + name_completion_case("Acsone", "Acsone for line", True), + name_completion_case("acsone", "Acsone for line", True), + name_completion_case("Acsone SA", "Line for Acsone SA test", True), + name_completion_case("Ac..ne", "Acsone for line", False), + name_completion_case("é@|r{}", "Acsone é@|r{} for line", True), + name_completion_case("Acsone", "A..one for line", False), + name_completion_case("A.one SA", "A.one SA for line", True), + name_completion_case("Acsone SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", False), + name_completion_case("Acsone ([^a-zA-Z0-9 -]) SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", True), + ] + + +class base_completion(common.TransactionCase): + + def setUp(self): + super(base_completion, self).setUp() + self.company_a = self.browse_ref('base.main_company') + self.profile_obj = self.registry("account.statement.profile") + self.partner_obj = self.registry("res.partner") + self.account_bank_statement_obj = self.registry("account.bank.statement") + self.account_bank_statement_line_obj = self.registry("account.bank.statement.line") + self.journal_id = self.ref("account.bank_journal") + self.partner_id = self.ref('base.main_partner') + self.account_id = self.ref("account.a_recv") + self.partner_id = self.ref("base.res_partner_12") + + def test_name_completion(self): + """Test complete partner_id from statement line label + Test the automatic completion of the partner_id based if the name of the partner appears in + the statement line label + """ + self.completion_rule_id = self.ref('account_statement_base_completion.bank_statement_completion_rule_3') + # Create the profile + self.profile_id = self.profile_obj.create(self.cr, self.uid, { + "name": "TEST", + "commission_account_id": self.account_id, + "journal_id": self.journal_id, + "rule_ids": [(6, 0, [self.completion_rule_id])]}) + # Create a bank statement + self.statement_id = self.account_bank_statement_obj.create(self.cr, self.uid, { + "balance_end_real": 0.0, + "balance_start": 0.0, + "date": time.strftime('%Y-%m-%d'), + "journal_id": self.journal_id, + "profile_id": self.profile_id + }) + + for case in NAMES_COMPLETION_CASES: + self.partner_obj.write(self.cr, self.uid, self.partner_id, {'name': case.partner_name}) + statement_line_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, { + 'amount': 1000.0, + 'name': case.line_label, + 'ref': 'My ref', + 'statement_id': self.statement_id, + }) + statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id) + self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion") + statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id) + statement_obj.button_auto_completion() + statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id) + if case.should_match: + self.assertEquals(self.partner_id, statement_line.partner_id['id'], + "Missing expected partner id after completion (partner_name: %s, line_name: %s)" % (case.partner_name, case.line_label)) + else: + self.assertNotEquals(self.partner_id, statement_line.partner_id['id'], + "Partner id should be empty after completion(partner_name: %s, line_name: %s)" % (case.partner_name, case.line_label)) From e80f498d67cf96ac49eda16849b6b2b6c108b7c7 Mon Sep 17 00:00:00 2001 From: Launchpad Translations on behalf of banking-addons-team Date: Thu, 20 Feb 2014 05:47:21 +0000 Subject: [PATCH 36/46] Launchpad automatic translations update. --- account_statement_regex_account_completion/i18n/fr.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_regex_account_completion/i18n/fr.po b/account_statement_regex_account_completion/i18n/fr.po index 4d414f52..ab5e74f6 100644 --- a/account_statement_regex_account_completion/i18n/fr.po +++ b/account_statement_regex_account_completion/i18n/fr.po @@ -13,7 +13,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2014-02-10 05:56+0000\n" +"X-Launchpad-Export-Date: 2014-02-20 05:47+0000\n" "X-Generator: Launchpad (build 16916)\n" #. module: account_statement_regex_account_completion From 106294d36367d6aab319c974dba0e466bda250f4 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:18:26 +0100 Subject: [PATCH 37/46] UPD account_advanced_reconcile_transaction_ref version --- account_advanced_reconcile_transaction_ref/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_advanced_reconcile_transaction_ref/__openerp__.py b/account_advanced_reconcile_transaction_ref/__openerp__.py index d806ba9e..bd1586cf 100644 --- a/account_advanced_reconcile_transaction_ref/__openerp__.py +++ b/account_advanced_reconcile_transaction_ref/__openerp__.py @@ -25,7 +25,7 @@ Advanced reconciliation method for the module account_easy_reconcile Reconcile rules with transaction_ref """, - 'version': '1.0', + 'version': '1.0.1', 'author': 'Camptocamp', 'category': 'Finance', 'website': 'http://www.camptocamp.com', From 0cedf1b84dc79d0f38bdce497f9664f85365ac8b Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:19:17 +0100 Subject: [PATCH 38/46] UPD account_statement_base_completion version --- account_statement_base_completion/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_completion/__openerp__.py b/account_statement_base_completion/__openerp__.py index d868a314..1ff18db7 100644 --- a/account_statement_base_completion/__openerp__.py +++ b/account_statement_base_completion/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## {'name': "Bank statement base completion", - 'version': '1.0', + 'version': '1.0.1', 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'category': 'Finance', From fc6032597b33960b15f8c292b935d37e035e373a Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:19:53 +0100 Subject: [PATCH 39/46] UPD account_statement_base_import version --- account_statement_base_import/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_import/__openerp__.py b/account_statement_base_import/__openerp__.py index 086af048..59a5a338 100644 --- a/account_statement_base_import/__openerp__.py +++ b/account_statement_base_import/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## {'name': "Bank statement base import", - 'version': '1.0', + 'version': '1.0.1', 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'category': 'Finance', From 3875378fc9229d1107f1683854327e998269b618 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:25:38 +0100 Subject: [PATCH 40/46] PEP8 on changes --- account_statement_ext/statement.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 48667715..4fa5b0df 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -202,7 +202,8 @@ class AccountBankStatement(Model): profile_obj = self.pool.get('account.statement.profile') profile = profile_obj.browse(cr, uid, vals['profile_id'], context=context) vals['journal_id'] = profile.journal_id.id - return super(AccountBankStatement, self).create(cr, uid, vals, context=context) + return super(AccountBankStatement, self + ).create(cr, uid, vals, context=context) def _get_period(self, cr, uid, date, context=None): """ @@ -243,8 +244,9 @@ class AccountBankStatement(Model): """ if context is None: context = {} - res = super(AccountBankStatement, self)._prepare_move( - cr, uid, st_line, st_line_number, context=context) + res = super(AccountBankStatement, self + )._prepare_move(cr, uid, st_line, st_line_number, + context=context) ctx = context.copy() ctx['company_id'] = st_line.company_id.id period_id = self._get_period(cr, uid, st_line.date, context=ctx) @@ -297,10 +299,9 @@ class AccountBankStatement(Model): create the move from. :return: int/long of the res.partner to use as counterpart """ - bank_partner_id = super(AccountBankStatement, self)._get_counter_part_partner(cr, - uid, - st_line, - context=context) + bank_partner_id = super(AccountBankStatement, self + )._get_counter_part_partner(cr, uid, st_line, + context=context) # get the right partner according to the chosen profile if st_line.statement_id.profile_id.force_partner_on_bank: bank_partner_id = st_line.statement_id.profile_id.partner_id.id @@ -530,8 +531,9 @@ class AccountBankStatement(Model): """ st = self.browse(cr, uid, st_id, context=context) if st.balance_check: - return super(AccountBankStatement, self).balance_check( - cr, uid, st_id, journal_type, context=context) + return super(AccountBankStatement, self + ).balance_check(cr, uid, st_id, journal_type, + context=context) else: return True @@ -684,11 +686,9 @@ class AccountBankStatementLine(Model): Keep the same features as in standard and call super. If an account is returned, call the method to compute line values. """ - res = super(AccountBankStatementLine, self).onchange_type(cr, uid, - line_id, - partner_id, - line_type, - context=context) + res = super(AccountBankStatementLine, self + ).onchange_type(cr, uid, line_id, partner_id, + line_type, context=context) if 'account_id' in res['value']: result = self.get_values_for_line(cr, uid, profile_id=profile_id, From 25e916cdcbdd0d007f6c742dda30473357f39ae7 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:26:17 +0100 Subject: [PATCH 41/46] UPD account_statement_ext version --- account_statement_ext/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_ext/__openerp__.py b/account_statement_ext/__openerp__.py index c6000063..32c518b9 100644 --- a/account_statement_ext/__openerp__.py +++ b/account_statement_ext/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## {'name': "Bank statement extension and profiles", - 'version': '1.3.0', + 'version': '1.3.1', 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'category': 'Finance', From da6c89f9dc603f66e1d275582f4803a186c59c18 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Mon, 24 Feb 2014 14:05:38 +0100 Subject: [PATCH 42/46] [REF] add TODO comment for using python exception --- account_statement_base_import/statement.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 3964d77c..e8cc6596 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -212,6 +212,9 @@ class AccountStatementProfil(Model): error_type, error_value, trbk = sys.exc_info() st = "Error: %s\nDescription: %s\nTraceback:" % (error_type.__name__, error_value) st += ''.join(traceback.format_tb(trbk, 30)) + #TODO we should catch correctly the exception with a python + #Exception and only re-catch some special exception. + #For now we avoid re-catching error in debug mode if config['debug_mode']: raise raise osv.except_osv(_("Statement import error"), From 51c76544454b4dcf0609eed95b6e2cdf36cc5960 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Mon, 24 Feb 2014 23:45:29 +0100 Subject: [PATCH 43/46] [FIX] account_statement_base_import: self reference calling method. --- account_statement_base_import/statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 3dbddd60..3ad5dbe4 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -36,7 +36,7 @@ class AccountStatementProfil(Model): return [('generic_csvxls_so', 'Generic .csv/.xls based on SO Name')] def _get_import_type_selection(self, cr, uid, context=None): - return get_import_type selection(cr, uid, context=context) + return self.get_import_type_selection(cr, uid, context=context) _columns = { 'launch_import_completion': fields.boolean( From ba824ca100af6ea5f8828bca610a8e09794e2e98 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 26 Feb 2014 11:23:37 +0100 Subject: [PATCH 44/46] the sample is insufficient to guess the delimiters on some files --- account_statement_base_import/parser/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index 39d4d313..cda1b539 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -25,7 +25,7 @@ import csv def UnicodeDictReader(utf8_data, **kwargs): sniffer = csv.Sniffer() pos = utf8_data.tell() - sample_data = utf8_data.read(1024) + sample_data = utf8_data.read(2048) utf8_data.seek(pos) dialect = sniffer.sniff(sample_data, delimiters=',;\t') csv_reader = csv.DictReader(utf8_data, dialect=dialect, **kwargs) From 512fd89093b5fb1b0c8f0ca22fbd662707bd4230 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 26 Feb 2014 12:02:40 +0100 Subject: [PATCH 45/46] restore default values to prevent regression introduced in pedro.baeza@serviciosbaeza.com-20140202105840-ndjvkvas1y82pxlw --- account_statement_base_import/parser/parser.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index 39d4d313..83fe9bd0 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -20,6 +20,7 @@ ############################################################################## import base64 import csv +from datetime import datetime def UnicodeDictReader(utf8_data, **kwargs): @@ -121,10 +122,10 @@ class BankStatementImportParser(object): :return: dict of vals that represent additional infos for the statement """ return { - 'name': self.statement_name, + 'name': self.statement_name or '/', 'balance_start': self.balance_start, 'balance_end_real': self.balance_end, - 'date': self.statement_date + 'date': self.statement_date or datetime.now() } def get_st_line_vals(self, line, *args, **kwargs): From c17afe17b1795332c979e5ed7dd8953713673afa Mon Sep 17 00:00:00 2001 From: Launchpad Translations on behalf of banking-addons-team Date: Sat, 1 Mar 2014 05:55:31 +0000 Subject: [PATCH 46/46] Launchpad automatic translations update. --- account_statement_regex_account_completion/i18n/fr.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_statement_regex_account_completion/i18n/fr.po b/account_statement_regex_account_completion/i18n/fr.po index ab5e74f6..b2bdf2a0 100644 --- a/account_statement_regex_account_completion/i18n/fr.po +++ b/account_statement_regex_account_completion/i18n/fr.po @@ -13,8 +13,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2014-02-20 05:47+0000\n" -"X-Generator: Launchpad (build 16916)\n" +"X-Launchpad-Export-Date: 2014-03-01 05:55+0000\n" +"X-Generator: Launchpad (build 16948)\n" #. module: account_statement_regex_account_completion #: field:account.statement.completion.rule,regex:0