From b65090bb41bfda3e803b1919684edacacd368def Mon Sep 17 00:00:00 2001 From: vrenaville Date: Wed, 3 Jun 2015 14:08:23 +0200 Subject: [PATCH 01/17] [ADD] account import line currency extension module --- .../__init__.py | 20 ++++++++ .../__openerp__.py | 51 +++++++++++++++++++ .../account_statement_from_invoice_view.xml | 50 ++++++++++++++++++ .../payment_view.xml | 48 +++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100644 account_import_line_multicurrency_extension/__init__.py create mode 100644 account_import_line_multicurrency_extension/__openerp__.py create mode 100644 account_import_line_multicurrency_extension/account_statement_from_invoice_view.xml create mode 100644 account_import_line_multicurrency_extension/payment_view.xml diff --git a/account_import_line_multicurrency_extension/__init__.py b/account_import_line_multicurrency_extension/__init__.py new file mode 100644 index 000000000..6dcc7ddba --- /dev/null +++ b/account_import_line_multicurrency_extension/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville (Camptocamp) +# Copyright 2015 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 . +# +############################################################################## diff --git a/account_import_line_multicurrency_extension/__openerp__.py b/account_import_line_multicurrency_extension/__openerp__.py new file mode 100644 index 000000000..6eec6852a --- /dev/null +++ b/account_import_line_multicurrency_extension/__openerp__.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville (Camptocamp) +# Copyright 2015 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': 'Payment Order Extension', + 'summary': 'Add an improved view for payment order', + 'version': '1.1', + 'author': "Camptocamp,Odoo Community Association (OCA)", + 'maintainter': 'Camptocamp', + 'category': 'Accounting', + 'depends': ['account_payment'], + 'description': """ +Payment Order +================== + +Add improved move line selection for multi-currency + +Contributors +------------ + +* Vincent revaville +""", + 'website': 'http://www.camptocamp.com', + 'data': ['payment_view.xml', + 'account_statement_from_invoice_view.xml', + ], + 'tests': [], + 'installable': True, + 'auto_install': False, + 'license': 'AGPL-3', + 'conflicts': [ + 'account_banking_payment_export', + ], + 'application': False, + } diff --git a/account_import_line_multicurrency_extension/account_statement_from_invoice_view.xml b/account_import_line_multicurrency_extension/account_statement_from_invoice_view.xml new file mode 100644 index 000000000..1382d8776 --- /dev/null +++ b/account_import_line_multicurrency_extension/account_statement_from_invoice_view.xml @@ -0,0 +1,50 @@ + + + + + + account.move.line.tree.bank.statement + account.move.line + + + + + + + + + + + + + + + + + account.statement.from.invoice.lines.form.over + account.statement.from.invoice.lines + + + + + + + + + + + + + + + + + + + + + + + diff --git a/account_import_line_multicurrency_extension/payment_view.xml b/account_import_line_multicurrency_extension/payment_view.xml new file mode 100644 index 000000000..e149a34a0 --- /dev/null +++ b/account_import_line_multicurrency_extension/payment_view.xml @@ -0,0 +1,48 @@ + + + + + + account.move.line.tree.payment + account.move.line + + + + + + + + + + + + + + + + + + payment.order.create.form.over + payment.order.create + + + + + + + + + + + + + + + + + + + + + + From 1b03b4b4f1f8490e222dd1a636456a68173a3eef Mon Sep 17 00:00:00 2001 From: vrenaville Date: Mon, 15 Jun 2015 13:49:21 +0200 Subject: [PATCH 02/17] [FIX] change layout --- .../__init__.py | 1 + .../__openerp__.py | 7 +- .../models/__init__.py | 22 ++++++ .../models/account_statement_from_invoice.py | 76 +++++++++++++++++++ .../models/bank_statement.py | 28 +++++++ .../account_statement_from_invoice_view.xml | 0 .../view/bank_statement_view.xml | 19 +++++ .../{ => view}/payment_view.xml | 0 8 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 account_import_line_multicurrency_extension/models/__init__.py create mode 100644 account_import_line_multicurrency_extension/models/account_statement_from_invoice.py create mode 100644 account_import_line_multicurrency_extension/models/bank_statement.py rename account_import_line_multicurrency_extension/{ => view}/account_statement_from_invoice_view.xml (100%) create mode 100644 account_import_line_multicurrency_extension/view/bank_statement_view.xml rename account_import_line_multicurrency_extension/{ => view}/payment_view.xml (100%) diff --git a/account_import_line_multicurrency_extension/__init__.py b/account_import_line_multicurrency_extension/__init__.py index 6dcc7ddba..563ca038e 100644 --- a/account_import_line_multicurrency_extension/__init__.py +++ b/account_import_line_multicurrency_extension/__init__.py @@ -18,3 +18,4 @@ # along with this program. If not, see . # ############################################################################## +from . import models diff --git a/account_import_line_multicurrency_extension/__openerp__.py b/account_import_line_multicurrency_extension/__openerp__.py index 6eec6852a..52c7dff99 100644 --- a/account_import_line_multicurrency_extension/__openerp__.py +++ b/account_import_line_multicurrency_extension/__openerp__.py @@ -24,7 +24,7 @@ 'author': "Camptocamp,Odoo Community Association (OCA)", 'maintainter': 'Camptocamp', 'category': 'Accounting', - 'depends': ['account_payment'], + 'depends': ['account_payment','account'], 'description': """ Payment Order ================== @@ -37,8 +37,9 @@ Contributors * Vincent revaville """, 'website': 'http://www.camptocamp.com', - 'data': ['payment_view.xml', - 'account_statement_from_invoice_view.xml', + 'data': ['view/payment_view.xml', + 'view/account_statement_from_invoice_view.xml', + 'view/bank_statement_view.xml', ], 'tests': [], 'installable': True, diff --git a/account_import_line_multicurrency_extension/models/__init__.py b/account_import_line_multicurrency_extension/models/__init__.py new file mode 100644 index 000000000..38ae6104b --- /dev/null +++ b/account_import_line_multicurrency_extension/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville (Camptocamp) +# Copyright 2015 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 . import bank_statement +from . import account_statement_from_invoice diff --git a/account_import_line_multicurrency_extension/models/account_statement_from_invoice.py b/account_import_line_multicurrency_extension/models/account_statement_from_invoice.py new file mode 100644 index 000000000..b7ea1a23b --- /dev/null +++ b/account_import_line_multicurrency_extension/models/account_statement_from_invoice.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville (Camptocamp) +# Copyright 2015 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 time + +from openerp.osv import fields, osv + +class account_statement_from_invoice_lines(osv.osv_memory): + """ + Generate Entries by Statement from Invoices + """ + _inherit = "account.statement.from.invoice.lines" + + + def populate_statement(self, cr, uid, ids, context=None): + context = dict(context or {}) + statement_id = context.get('statement_id', False) + if not statement_id: + return {'type': 'ir.actions.act_window_close'} + data = self.read(cr, uid, ids, context=context)[0] + line_ids = data['line_ids'] + if not line_ids: + return {'type': 'ir.actions.act_window_close'} + + line_obj = self.pool.get('account.move.line') + statement_obj = self.pool.get('account.bank.statement') + statement_line_obj = self.pool.get('account.bank.statement.line') + currency_obj = self.pool.get('res.currency') + statement = statement_obj.browse(cr, uid, statement_id, context=context) + line_date = statement.date + + # for each selected move lines + for line in line_obj.browse(cr, uid, line_ids, context=context): + ctx = context.copy() + # take the date for computation of currency => use payment date + ctx['date'] = line_date + amount = 0.0 + amount_currency = 0.0 + if line.invoice and line.invoice.currency_id == statement.currency_id: + amount = line.amount_residual_currency + amount_currency = 0.0 + else: + amount = 0.0 + amount_currency = line.amount_residual_currency + + context.update({'move_line_ids': [line.id], + 'invoice_id': line.invoice.id}) + + statement_line_obj.create(cr, uid, { + 'name': line.name or '?', + 'amount': amount, + 'partner_id': line.partner_id.id, + 'statement_id': statement_id, + 'ref': line.ref, + 'date': statement.date, + 'amount_currency': amount_currency, + 'currency_id': line.currency_id.id, + }, context=context) + return {'type': 'ir.actions.act_window_close'} diff --git a/account_import_line_multicurrency_extension/models/bank_statement.py b/account_import_line_multicurrency_extension/models/bank_statement.py new file mode 100644 index 000000000..20ecd12c8 --- /dev/null +++ b/account_import_line_multicurrency_extension/models/bank_statement.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville (Camptocamp) +# Copyright 2015 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 import models, fields + + +class AccountBankStatementLine(models.Model): + _inherit = "account.bank.statement.line" + + currency_symbol = fields.Char( + related='statement_id.currency.symbol', readonly=True) diff --git a/account_import_line_multicurrency_extension/account_statement_from_invoice_view.xml b/account_import_line_multicurrency_extension/view/account_statement_from_invoice_view.xml similarity index 100% rename from account_import_line_multicurrency_extension/account_statement_from_invoice_view.xml rename to account_import_line_multicurrency_extension/view/account_statement_from_invoice_view.xml diff --git a/account_import_line_multicurrency_extension/view/bank_statement_view.xml b/account_import_line_multicurrency_extension/view/bank_statement_view.xml new file mode 100644 index 000000000..e57765805 --- /dev/null +++ b/account_import_line_multicurrency_extension/view/bank_statement_view.xml @@ -0,0 +1,19 @@ + + + + + + account.bank.statement.form.inherit + account.bank.statement + form + + + + + + + + + + + diff --git a/account_import_line_multicurrency_extension/payment_view.xml b/account_import_line_multicurrency_extension/view/payment_view.xml similarity index 100% rename from account_import_line_multicurrency_extension/payment_view.xml rename to account_import_line_multicurrency_extension/view/payment_view.xml From eef85a693672467804ad0c15a0d831430da8a0cb Mon Sep 17 00:00:00 2001 From: vrenaville Date: Fri, 26 Jun 2015 10:58:37 +0200 Subject: [PATCH 03/17] [FIX] Import invoice view improvement --- .../models/account_statement_from_invoice.py | 60 ++++++++++--------- .../models/bank_statement.py | 29 ++++++++- .../account_statement_from_invoice_view.xml | 2 +- .../view/bank_statement_view.xml | 3 + 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/account_import_line_multicurrency_extension/models/account_statement_from_invoice.py b/account_import_line_multicurrency_extension/models/account_statement_from_invoice.py index b7ea1a23b..0862b8884 100644 --- a/account_import_line_multicurrency_extension/models/account_statement_from_invoice.py +++ b/account_import_line_multicurrency_extension/models/account_statement_from_invoice.py @@ -20,57 +20,59 @@ ############################################################################## import time -from openerp.osv import fields, osv +from openerp import fields, models, api, _ -class account_statement_from_invoice_lines(osv.osv_memory): +class account_statement_from_invoice_lines(models.TransientModel): """ Generate Entries by Statement from Invoices """ _inherit = "account.statement.from.invoice.lines" - - - def populate_statement(self, cr, uid, ids, context=None): - context = dict(context or {}) - statement_id = context.get('statement_id', False) + + @api.multi + def populate_statement(self): + statement_id = self.env.context.get('statement_id', False) if not statement_id: return {'type': 'ir.actions.act_window_close'} - data = self.read(cr, uid, ids, context=context)[0] - line_ids = data['line_ids'] - if not line_ids: + if not self.line_ids: return {'type': 'ir.actions.act_window_close'} - line_obj = self.pool.get('account.move.line') - statement_obj = self.pool.get('account.bank.statement') - statement_line_obj = self.pool.get('account.bank.statement.line') - currency_obj = self.pool.get('res.currency') - statement = statement_obj.browse(cr, uid, statement_id, context=context) + line_obj = self.env['account.move.line'] + statement_obj = self.env['account.bank.statement'] + statement_line_obj = self.env['account.bank.statement.line'] + currency_obj = self.env['res.currency'] + statement = statement_obj.browse(statement_id) line_date = statement.date + # Get the currency on the company if not set on the journal + if statement.journal_id.currency: + from_currency_id = statement.journal_id.currency + else: + from_currency_id = self.env.user.company_id.currency_id # for each selected move lines - for line in line_obj.browse(cr, uid, line_ids, context=context): - ctx = context.copy() - # take the date for computation of currency => use payment date - ctx['date'] = line_date - amount = 0.0 - amount_currency = 0.0 - if line.invoice and line.invoice.currency_id == statement.currency_id: + for line in self.line_ids: + if line.invoice and line.invoice.currency_id == from_currency_id: amount = line.amount_residual_currency amount_currency = 0.0 else: - amount = 0.0 + if statement.journal_id.currency: + from_currency_id = statement.journal_id.currency + else: + from_currency_id = self.env.user.company_id.currency_id + amount = from_currency_id.with_context(date=line_date).compute(line.amount_residual_currency, + line.invoice.currency_id) amount_currency = line.amount_residual_currency - - context.update({'move_line_ids': [line.id], + ctx = {} + ctx.update({'move_line_ids': [line.id], 'invoice_id': line.invoice.id}) - statement_line_obj.create(cr, uid, { - 'name': line.name or '?', + statement_line_obj.with_context(ctx).create({ + 'name': line.ref or '?', 'amount': amount, 'partner_id': line.partner_id.id, 'statement_id': statement_id, - 'ref': line.ref, + 'ref': line.name, 'date': statement.date, 'amount_currency': amount_currency, 'currency_id': line.currency_id.id, - }, context=context) + }) return {'type': 'ir.actions.act_window_close'} diff --git a/account_import_line_multicurrency_extension/models/bank_statement.py b/account_import_line_multicurrency_extension/models/bank_statement.py index 20ecd12c8..bc03c4f4a 100644 --- a/account_import_line_multicurrency_extension/models/bank_statement.py +++ b/account_import_line_multicurrency_extension/models/bank_statement.py @@ -18,11 +18,38 @@ # along with this program. If not, see . # ############################################################################## -from openerp import models, fields +from openerp import models, fields, api, exceptions, _ class AccountBankStatementLine(models.Model): _inherit = "account.bank.statement.line" currency_symbol = fields.Char( + string='Journal Currency', related='statement_id.currency.symbol', readonly=True) + + +class AccountBankStatement(models.Model): + _inherit = "account.bank.statement" + + @api.multi + def check_line_amount_zero(self): + self.ensure_one() + msg = '' + for line in self.line_ids: + if not line.amount: + msg += 'Amount on line %s is not set. \n' % (line.name) + if msg: + raise exceptions.Warning( + _("Error on bank statement: \n %s") % msg) + # dispatch to reconciliation interface + action = self.env.ref( + 'account.action_bank_reconcile_bank_statements') + return { + 'name': action.name, + 'tag': action.tag, + 'context': { + 'statement_ids': self.ids, + }, + 'type': 'ir.actions.client', + } diff --git a/account_import_line_multicurrency_extension/view/account_statement_from_invoice_view.xml b/account_import_line_multicurrency_extension/view/account_statement_from_invoice_view.xml index 1382d8776..21f6c10fc 100644 --- a/account_import_line_multicurrency_extension/view/account_statement_from_invoice_view.xml +++ b/account_import_line_multicurrency_extension/view/account_statement_from_invoice_view.xml @@ -28,7 +28,7 @@ + domain="[('account_id.type','in',['receivable','payable']),('journal_id.type','in',['sale','purchase','sale_refund','purchase_refund']), ('reconcile_id','=',False), ('state', '=', 'valid')]"> diff --git a/account_import_line_multicurrency_extension/view/bank_statement_view.xml b/account_import_line_multicurrency_extension/view/bank_statement_view.xml index e57765805..8397cdc84 100644 --- a/account_import_line_multicurrency_extension/view/bank_statement_view.xml +++ b/account_import_line_multicurrency_extension/view/bank_statement_view.xml @@ -11,6 +11,9 @@ + +