diff --git a/account_payment_transaction_id/__openerp__.py b/account_payment_transaction_id/__openerp__.py index 32f735a2..b69c1dd2 100644 --- a/account_payment_transaction_id/__openerp__.py +++ b/account_payment_transaction_id/__openerp__.py @@ -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': [], diff --git a/account_payment_transaction_id/account_payment.py b/account_payment_transaction_id/account_payment.py index 1ddfe268..227a61a8 100644 --- a/account_payment_transaction_id/account_payment.py +++ b/account_payment_transaction_id/account_payment.py @@ -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 diff --git a/statement_voucher_killer/voucher.py b/statement_voucher_killer/voucher.py index 6cc27608..d01c0b84 100644 --- a/statement_voucher_killer/voucher.py +++ b/statement_voucher_killer/voucher.py @@ -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) + }