add account_payment_transaction_id: compatibility between payment orders and transaction ids

This commit is contained in:
Guewen Baconnier
2014-03-04 16:46:05 +01:00
parent f74149fb47
commit 981167d28c
3 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import account_payment

View File

@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Guewen Baconnier
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{'name': 'Account Payment - Transaction ID',
'version': 'version',
'author': 'Camptocamp',
'maintainer': 'Camptocamp',
'license': 'AGPL-3',
'category': 'Hidden',
'depends': ['base_transaction_id',
'account_payment',
],
'description': """
Compatibility module between Account Payment and Base Transaction ID
""",
'website': 'http://www.camptocamp.com',
'data': [],
'test': [],
'installable': True,
'auto_install': True,
}

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Guewen Baconnier
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
class payment_line(orm.Model):
_inherit = 'payment.line'
def _update_transaction_id(self, cr, uid, ids, context=None):
""" Update the bank statement line's transaction id
When the payment line is linked with a bank statement line,
copy the transaction id of the related move line.
"""
if isinstance(ids, (int, long)):
ids = [ids]
for line in self.browse(cr, uid, ids, context=context):
if not line.move_line_id:
continue
if not line.bank_statement_line_id:
continue
stat_trans_id = line.bank_statement_line_id.transaction_id
move_trans_id = line.move_line_id.transaction_ref
if stat_trans_id != move_trans_id:
line.bank_statement_line_id.write(
{'transaction_id': move_trans_id}
)
def create(self, cr, uid, vals, context=None):
line_id = super(payment_line, self).create(cr, uid, vals,
context=context)
if vals.get('bank_statement_line_id'):
self._update_transaction_id(cr, uid, [line_id], context=context)
return line_id
def write(self, cr, uid, ids, vals, context=None):
result = super(payment_line, self).write(cr, uid, ids, vals,
context=context)
if vals.get('bank_statement_line_id'):
self._update_transaction_id(cr, uid, ids, context=context)
return result