From 86a2c22dde13b517ec16be61ac40bb6c4618856a Mon Sep 17 00:00:00 2001 From: vrenaville Date: Mon, 24 Nov 2014 11:47:50 +0100 Subject: [PATCH] [ADD] account_payment_multicurrency module --- .../__init__.py | 21 +++++ .../__openerp__.py | 46 +++++++++++ .../payment.py | 80 +++++++++++++++++++ .../payment_view.xml | 48 +++++++++++ 4 files changed, 195 insertions(+) create mode 100644 account_payment_multicurrency_extension/__init__.py create mode 100644 account_payment_multicurrency_extension/__openerp__.py create mode 100644 account_payment_multicurrency_extension/payment.py create mode 100644 account_payment_multicurrency_extension/payment_view.xml diff --git a/account_payment_multicurrency_extension/__init__.py b/account_payment_multicurrency_extension/__init__.py new file mode 100644 index 000000000..9c71ebcab --- /dev/null +++ b/account_payment_multicurrency_extension/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville (Camptocamp) +# Copyright 2010-2014 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 payment diff --git a/account_payment_multicurrency_extension/__openerp__.py b/account_payment_multicurrency_extension/__openerp__.py new file mode 100644 index 000000000..5c21047a8 --- /dev/null +++ b/account_payment_multicurrency_extension/__openerp__.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville (Camptocamp) +# Copyright 2010-2014 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', + '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'], + 'tests': [], + 'installable': True, + 'auto_install': False, + 'license': 'AGPL-3', + 'application': False, + } diff --git a/account_payment_multicurrency_extension/payment.py b/account_payment_multicurrency_extension/payment.py new file mode 100644 index 000000000..e8611cdd8 --- /dev/null +++ b/account_payment_multicurrency_extension/payment.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville +# Copyright 2014 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.osv import orm + + +class payment_order_create(orm.TransientModel): + + _inherit = 'payment.order.create' + + def create_payment(self, cr, uid, ids, context=None): + """ + We recreate function to be able set + 'amount_currency': line.amount_residual_currency + instead of + 'amount_currency': line.amount_to_pay + To be compliant with multi currency + Allready corrected in V8 but will not be corrected in V7 + """ + order_obj = self.pool.get('payment.order') + line_obj = self.pool.get('account.move.line') + payment_obj = self.pool.get('payment.line') + if context is None: + context = {} + data = self.browse(cr, uid, ids, context=context)[0] + line_ids = [entry.id for entry in data.entries] + if not line_ids: + return {'type': 'ir.actions.act_window_close'} + + payment = order_obj.browse(cr, uid, context['active_id'], + context=context) + line2bank = line_obj.line2bank(cr, uid, line_ids, None, context) + + # Finally populate the current payment with new lines: + for line in line_obj.browse(cr, uid, line_ids, context=context): + if payment.date_prefered == "now": + # no payment date => immediate payment + date_to_pay = False + elif payment.date_prefered == 'due': + date_to_pay = line.date_maturity + elif payment.date_prefered == 'fixed': + date_to_pay = payment.date_scheduled + state = 'normal' + if line.invoice and line.invoice.reference_type != 'none': + state = 'structured' + currency_id = line.invoice.currency_id.id if line.invoice else None + if not currency_id: + currency_id = line.journal_id.currency.id + if not currency_id: + currency_id = line.journal_id.company_id.currency_id.id + payment_obj.create( + cr, uid, { + 'move_line_id': line.id, + 'amount_currency': line.amount_residual_currency, + 'bank_id': line2bank.get(line.id), + 'order_id': payment.id, + 'partner_id': line.partner_id.id, + 'communication': line.ref or '/', + 'state': state, + 'date': date_to_pay, + 'currency': currency_id, + }, context=context) + return {'type': 'ir.actions.act_window_close'} diff --git a/account_payment_multicurrency_extension/payment_view.xml b/account_payment_multicurrency_extension/payment_view.xml new file mode 100644 index 000000000..7a4f36390 --- /dev/null +++ b/account_payment_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 + + + + + + + + + + + + + + + + + + + + + +