diff --git a/account_statement_base_import/__openerp__.py b/account_statement_base_import/__openerp__.py index c9f6e1b5..086af048 100644 --- a/account_statement_base_import/__openerp__.py +++ b/account_statement_base_import/__openerp__.py @@ -47,7 +47,6 @@ in the generated entries and will be useful for reconciliation process * date : date of the payment * amount : amount paid in the currency of the journal used in the importation profile - * commission_amount : amount of the comission for each line * label : the comunication given by the payment office, used as communication in the generated entries. diff --git a/account_statement_base_import/wizard/import_statement.py b/account_statement_base_import/wizard/import_statement.py index 80ea291e..b6960ec9 100644 --- a/account_statement_base_import/wizard/import_statement.py +++ b/account_statement_base_import/wizard/import_statement.py @@ -55,10 +55,6 @@ class CreditPartnerStatementImporter(orm.TransientModel): 'journal_id': fields.many2one('account.journal', 'Financial journal to use transaction'), 'file_name': fields.char('File Name', size=128), - 'commission_account_id': fields.many2one('account.account', - 'Commission account'), - 'commission_analytic_id': fields.many2one('account.analytic.account', - 'Commission analytic account'), 'receivable_account_id': fields.many2one('account.account', 'Force Receivable/Payable Account'), 'force_partner_on_bank': fields.boolean( @@ -80,10 +76,7 @@ class CreditPartnerStatementImporter(orm.TransientModel): res = {'value': {'partner_id': c.partner_id and c.partner_id.id or False, 'journal_id': c.journal_id and c.journal_id.id or False, - 'commission_account_id': - c.commission_account_id and c.commission_account_id.id or False, 'receivable_account_id': c.receivable_account_id and c.receivable_account_id.id or False, - 'commission_a': c.commission_analytic_id and c.commission_analytic_id.id or False, 'force_partner_on_bank': c.force_partner_on_bank, 'balance_check': c.balance_check, } diff --git a/account_statement_base_import/wizard/import_statement_view.xml b/account_statement_base_import/wizard/import_statement_view.xml index 57fd8476..51ec4740 100644 --- a/account_statement_base_import/wizard/import_statement_view.xml +++ b/account_statement_base_import/wizard/import_statement_view.xml @@ -14,8 +14,6 @@ - - diff --git a/account_statement_commission/__init__.py b/account_statement_commission/__init__.py new file mode 100644 index 00000000..5ba29072 --- /dev/null +++ b/account_statement_commission/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Joel Grand-Guillaume +# Copyright 2011-2012 Camptocamp SA +# Copyright 2013 Savoir-faire Linux () +# +# 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 commission diff --git a/account_statement_commission/__openerp__.py b/account_statement_commission/__openerp__.py new file mode 100644 index 00000000..9d22eab5 --- /dev/null +++ b/account_statement_commission/__openerp__.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Joel Grand-Guillaume +# Copyright 2011-2012 Camptocamp SA +# Copyright 2013 Savoir-faire Linux () +# +# 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 import - commissions", + 'version': '1.0', + 'author': 'Camptocamp', + 'maintainer': 'Camptocamp', + 'category': 'Finance', + 'complexity': 'normal', + 'depends': [ + 'account_statement_base_import' + ], + 'description': """ +This module brings commission support to bank statement imports. It computes the sum of a commission +field on each transaction and creates a statement entry for it. +""", +'website': 'http://www.camptocamp.com', +'data': [ + "statement_view.xml", + "import_statement_view.xml", +], +'test': [], +'installable': True, +'images': [], +'auto_install': False, +'license': 'AGPL-3', +} diff --git a/account_statement_commission/commission.py b/account_statement_commission/commission.py index ce928b41..138ad61f 100644 --- a/account_statement_commission/commission.py +++ b/account_statement_commission/commission.py @@ -1,9 +1,11 @@ from openerp.tools.translate import _ import datetime -from openerp.osv import fields -from openerp.osv.orm import Model +from openerp.osv import orm, fields -class AccountStatementProfil(Model): +def float_or_zero(val): + return float(val) if val else 0.0 + +class AccountStatementProfil(orm.Model): _inherit = "account.statement.profile" def _write_extra_statement_lines( @@ -12,7 +14,7 @@ class AccountStatementProfil(Model): """ global_commission_amount = 0 for row in parser.result_row_list: - global_commission_amount += row.get('commission_amount', 0.0) + global_commission_amount += float_or_zero(row.get('commission_amount', '0.0')) if not global_commission_amount: return partner_id = profile.partner_id and profile.partner_id.id or False @@ -34,7 +36,7 @@ class AccountStatementProfil(Model): statement_line_obj = self.pool.get('account.bank.statement.line') statement_line_obj.create(cr, uid, comm_values, context=context) -class AccountStatementLineWithCommission(Model): +class AccountStatementLineWithCommission(orm.Model): _inherit = "account.bank.statement.line" _columns = { 'commission_amount': fields.sparse( @@ -42,3 +44,25 @@ class AccountStatementLineWithCommission(Model): string='Line Commission Amount', serialization_field='additionnal_bank_fields'), } + +class CreditPartnerStatementImporter(orm.TransientModel): + _inherit = "credit.statement.import" + + _columns = { + 'commission_account_id': fields.many2one('account.account', + 'Commission account'), + 'commission_analytic_id': fields.many2one('account.analytic.account', + 'Commission analytic account'), + } + + def onchange_profile_id(self, cr, uid, ids, profile_id, context=None): + res = super(CreditPartnerStatementImporter, self).onchange_profile_id( + cr, uid, ids, profile_id, context=context) + if profile_id: + c = self.pool.get("account.statement.profile").browse( + cr, uid, profile_id, context=context) + res['value']['commission_account_id'] = \ + c.commission_account_id and c.commission_account_id.id or False + res['value']['commission_a'] = \ + c.commission_analytic_id and c.commission_analytic_id.id or False + return res \ No newline at end of file diff --git a/account_statement_commission/import_statement_view.xml b/account_statement_commission/import_statement_view.xml new file mode 100644 index 00000000..45413b4f --- /dev/null +++ b/account_statement_commission/import_statement_view.xml @@ -0,0 +1,18 @@ + + + + + credit.statement.import.config.view + credit.statement.import + form + + + + + + + + + + +