mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
module now depends on statement_voucher_killer, and this module adds hooks in the generation of statement lines so we can add the transaction ids
This commit is contained in:
@@ -21,16 +21,19 @@
|
||||
|
||||
|
||||
{'name': 'Account Payment - Transaction ID',
|
||||
'version': 'version',
|
||||
'version': '1.0',
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Hidden',
|
||||
'depends': ['base_transaction_id',
|
||||
'account_payment',
|
||||
'statement_voucher_killer',
|
||||
],
|
||||
'description': """
|
||||
Compatibility module between Account Payment and Base Transaction ID
|
||||
Compatibility module between Account Payment and Base Transaction ID.
|
||||
|
||||
Needs `statement_voucher_killer`
|
||||
""",
|
||||
'website': 'http://www.camptocamp.com',
|
||||
'data': [],
|
||||
|
||||
@@ -22,41 +22,26 @@
|
||||
from openerp.osv import orm
|
||||
|
||||
|
||||
class payment_line(orm.Model):
|
||||
_inherit = 'payment.line'
|
||||
class AccountPaymentPopulateStatement(orm.TransientModel):
|
||||
_inherit = "account.payment.populate.statement"
|
||||
|
||||
def _update_transaction_id(self, cr, uid, ids, context=None):
|
||||
""" Update the bank statement line's transaction id
|
||||
def _prepare_statement_line_vals(self, cr, uid, payment_line, amount,
|
||||
statement, context=None):
|
||||
superself = super(AccountPaymentPopulateStatement, self)
|
||||
vals = superself._prepare_statement_line_vals(
|
||||
cr, uid, payment_line, amount, statement, context=context)
|
||||
if payment_line.move_line_id:
|
||||
vals['transaction_id'] = payment_line.move_line_id.transaction_ref
|
||||
return vals
|
||||
|
||||
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
|
||||
class account_statement_from_invoice_lines(orm.TransientModel):
|
||||
_inherit = "account.statement.from.invoice.lines"
|
||||
|
||||
def _prepare_statement_line_vals(self, cr, uid, move_line, s_type,
|
||||
statement_id, amount, context=None):
|
||||
superself = super(account_statement_from_invoice_lines, self)
|
||||
vals = superself._prepare_statement_line_vals(
|
||||
cr, uid, move_line, s_type, statement_id, amount, context=context)
|
||||
vals['transaction_id'] = move_line.transaction_ref
|
||||
return vals
|
||||
|
||||
@@ -72,18 +72,23 @@ class AccountStatementFromInvoiceLines(orm.TransientModel):
|
||||
s_type = 'customer'
|
||||
elif line.journal_id.type in ('purchase', 'purhcase_refund'):
|
||||
s_type = 'supplier'
|
||||
statement_line_obj.create(cr, uid, {
|
||||
'name': line.name or '?',
|
||||
vals = self._prepare_statement_line_vals(
|
||||
cr, uid, line, s_type, statement_id, amount, context=context)
|
||||
statement_line_obj.create(cr, uid, vals, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def _prepare_statement_line_vals(self, cr, uid, move_line, s_type,
|
||||
statement_id, amount, context=None):
|
||||
return {'name': move_line.name or '?',
|
||||
'amount': amount,
|
||||
'type': s_type,
|
||||
'partner_id': line.partner_id.id,
|
||||
'account_id': line.account_id.id,
|
||||
'partner_id': move_line.partner_id.id,
|
||||
'account_id': move_line.account_id.id,
|
||||
'statement_id': statement_id,
|
||||
'ref': line.ref,
|
||||
'ref': move_line.ref,
|
||||
'voucher_id': False,
|
||||
'date': time.strftime('%Y-%m-%d'),
|
||||
}, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
}
|
||||
|
||||
|
||||
class AccountPaymentPopulateStatement(orm.TransientModel):
|
||||
@@ -114,16 +119,23 @@ class AccountPaymentPopulateStatement(orm.TransientModel):
|
||||
if not line.move_line_id.id:
|
||||
continue
|
||||
context.update({'move_line_ids': [line.move_line_id.id]})
|
||||
st_line_id = statement_line_obj.create(cr, uid, {
|
||||
'name': line.order_id.reference or '?',
|
||||
'amount': - amount,
|
||||
'type': 'supplier',
|
||||
'partner_id': line.partner_id.id,
|
||||
'account_id': line.move_line_id.account_id.id,
|
||||
'statement_id': statement.id,
|
||||
'ref': line.communication,
|
||||
'date': line.date or line.ml_maturity_date or statement.date,
|
||||
}, context=context)
|
||||
vals = self._prepare_statement_line_vals(
|
||||
cr, uid, line, -amount, statement, context=context)
|
||||
st_line_id = statement_line_obj.create(cr, uid, vals,
|
||||
context=context)
|
||||
|
||||
line_obj.write(cr, uid, [line.id], {'bank_statement_line_id': st_line_id})
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def _prepare_statement_line_vals(self, cr, uid, payment_line, amount,
|
||||
statement, context=None):
|
||||
return {'name': payment_line.order_id.reference or '?',
|
||||
'amount': amount,
|
||||
'type': 'supplier',
|
||||
'partner_id': payment_line.partner_id.id,
|
||||
'account_id': payment_line.move_line_id.account_id.id,
|
||||
'statement_id': statement.id,
|
||||
'ref': payment_line.communication,
|
||||
'date': (payment_line.date or payment_line.ml_maturity_date or
|
||||
statement.date)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user