mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[RFR] split off transaction wizard ORM model
[FIX] cannot cancel a bank statement [FIX] cannot confirm bank statement lines that need no reconciliaton
This commit is contained in:
@@ -668,6 +668,8 @@ class banking_import_transaction(osv.osv):
|
||||
if ids and isinstance(ids, (int, float)):
|
||||
ids = [ids]
|
||||
for transaction in self.browse(cr, uid, ids, context):
|
||||
if not transaction.match_type:
|
||||
continue
|
||||
if transaction.match_type not in self.cancel_map:
|
||||
raise osv.except_osv(
|
||||
_("Cannot cancel type %s" % transaction.match_type),
|
||||
@@ -685,6 +687,8 @@ class banking_import_transaction(osv.osv):
|
||||
if ids and isinstance(ids, (int, float)):
|
||||
ids = [ids]
|
||||
for transaction in self.browse(cr, uid, ids, context):
|
||||
if not transaction.match_type:
|
||||
continue
|
||||
if transaction.match_type not in self.reconcile_map:
|
||||
raise osv.except_osv(
|
||||
_("Cannot reconcile type %s" % transaction.match_type),
|
||||
@@ -1363,186 +1367,6 @@ class banking_import_transaction(osv.osv):
|
||||
}
|
||||
banking_import_transaction()
|
||||
|
||||
class banking_transaction_wizard(osv.osv_memory):
|
||||
_name = 'banking.transaction.wizard'
|
||||
_description = 'Match transaction'
|
||||
|
||||
def create_act_window(self, cr, uid, ids, nodestroy=True, context=None):
|
||||
if isinstance(ids, (int, float)):
|
||||
ids = [ids]
|
||||
return {
|
||||
'name': self._description,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': self._name,
|
||||
'domain': [],
|
||||
'context': context,
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
'res_id': ids[0],
|
||||
'nodestroy': nodestroy,
|
||||
}
|
||||
|
||||
def trigger_match(self, cr, uid, ids, context=None):
|
||||
if isinstance(ids, (int, float)):
|
||||
ids = [ids]
|
||||
import_transaction_obj = self.pool.get('banking.import.transaction')
|
||||
trans_id = self.read(
|
||||
cr, uid, ids[0], ['import_transaction_id'],
|
||||
context=context)['import_transaction_id'][0] # many2one tuple
|
||||
|
||||
import_transaction_obj.match(cr, uid, [trans_id], context=context)
|
||||
return True
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
res = super(banking_transaction_wizard, self).write(
|
||||
cr, uid, ids, vals, context=context)
|
||||
if vals and 'invoice_id' in vals:
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
transaction_obj = self.pool.get('banking.import.transaction')
|
||||
for wiz in self.browse(cr, uid, ids, context=context):
|
||||
if (wiz.import_transaction_id.match_type == 'invoice' and
|
||||
wiz.import_transaction_id.invoice_id):
|
||||
if (wiz.move_line_id and wiz.move_line_id.invoice and
|
||||
wiz.move_line_id.invoice.id == wiz.invoice_id.id):
|
||||
found = True
|
||||
continue
|
||||
for move_line in wiz.import_transaction_id.move_line_ids:
|
||||
if (move_line.invoice.id ==
|
||||
wiz.import_transaction_id.invoice_id.id):
|
||||
transaction_obj.write(
|
||||
cr, uid, wiz.import_transaction_id.id,
|
||||
{ 'move_line_id': move_line.id, }, context=context)
|
||||
statement_line_obj.write(
|
||||
cr, uid, wiz.import_transaction_id.statement_line_id.id,
|
||||
{ 'partner_id': move_line.invoice.partner_id.id,
|
||||
'account_id': move_line.account_id.id,
|
||||
}, context=context)
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
transaction_obj.write(
|
||||
cr, uid, wiz.import_transaction_id.id,
|
||||
{ 'invoice_id': False, }, context=context)
|
||||
# osv.except_osv(
|
||||
# _("No entry found for the selected invoice"),
|
||||
# _("Please file a bug and resort to manual matching."))
|
||||
|
||||
def select_match(self, cr, uid, ids, context=None):
|
||||
return True
|
||||
# TODO: indicate residual
|
||||
# The procedure below has been moved to write()
|
||||
if isinstance(ids, (int, float)):
|
||||
ids = [ids]
|
||||
transaction_obj = self.pool.get('banking.import.transaction')
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
found = False
|
||||
for wiz in self.browse(cr, uid, ids, context=context):
|
||||
if (wiz.import_transaction_id.match_type == 'invoice' and
|
||||
wiz.import_transaction_id.invoice_id):
|
||||
for move_line in wiz.import_transaction_id.move_line_ids:
|
||||
if (move_line.invoice.id ==
|
||||
wiz.import_transaction_id.invoice_id.id):
|
||||
transaction_obj.write(
|
||||
cr, uid, wiz.import_transaction_id.id,
|
||||
{ 'move_line_id': move_line.id, }, context=context)
|
||||
statement_line_obj.write(
|
||||
cr, uid, wiz.import_transaction_id.statement_line_id.id,
|
||||
{ 'partner_id': move_line.invoice.partner_id.id,
|
||||
'account_id': move_line.account_id.id,
|
||||
}, context=context)
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
transaction_obj.write(
|
||||
cr, uid, wiz.import_transaction_id.id,
|
||||
{ 'invoice_id': False, }, context=context)
|
||||
# osv.except_osv(
|
||||
# _("No entry found for the selected invoice"),
|
||||
# _("Please file a bug and resort to manual matching."))
|
||||
return True
|
||||
|
||||
def reverse_duplicate(self, cr, uid, ids, context=None):
|
||||
if isinstance(ids, (int, float)):
|
||||
ids = [ids]
|
||||
transaction_obj = self.pool.get('banking.import.transaction')
|
||||
for wiz in self.read(cr, uid, ids, ['duplicate', 'import_transaction_id'], context=context):
|
||||
transaction_obj.write(
|
||||
cr, uid, wiz['import_transaction_id'][0],
|
||||
{'duplicate': not wiz['duplicate']}, context=context)
|
||||
return True
|
||||
|
||||
def _get_default_match_type(self, cr, uid, context=None):
|
||||
res = False
|
||||
if context and 'statement_line_id' in context:
|
||||
res = self.pool.get('account.bank.statement.line').read(
|
||||
cr, uid, context['statement_line_id'],
|
||||
['match_type'], context=context)['match_type']
|
||||
return res
|
||||
|
||||
def button_done(self, cr, uid, ids, context=None):
|
||||
return {'nodestroy': False, 'type': 'ir.actions.act_window_close'}
|
||||
|
||||
_defaults = {
|
||||
'match_type': _get_default_match_type,
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64),
|
||||
'statement_line_id': fields.many2one(
|
||||
'account.bank.statement.line', 'Statement line',
|
||||
),
|
||||
'amount': fields.related(
|
||||
'statement_line_id', 'amount', type='float',
|
||||
string="Amount", readonly=True),
|
||||
'import_transaction_id': fields.related(
|
||||
'statement_line_id', 'import_transaction_id',
|
||||
string="Import transaction",
|
||||
type='many2one', relation='banking.import.transaction'),
|
||||
'payment_line_id': fields.related(
|
||||
'import_transaction_id', 'payment_line_id', string="Matching payment or storno",
|
||||
type='many2one', relation='payment.line'),
|
||||
'payment_order_ids': fields.related(
|
||||
'import_transaction_id', 'payment_order_ids', string="Matching payment orders",
|
||||
type='many2many', relation='payment.order'),
|
||||
'payment_order_id': fields.related(
|
||||
'import_transaction_id', 'payment_order_id', string="Payment order to reconcile",
|
||||
type='many2one', relation='payment.order'),
|
||||
'invoice_ids': fields.related(
|
||||
'import_transaction_id', 'invoice_ids', string="Matching invoices",
|
||||
type='many2many', relation='account.invoice'),
|
||||
'invoice_id': fields.related(
|
||||
'import_transaction_id', 'invoice_id', string="Invoice to reconcile",
|
||||
type='many2one', relation='account.invoice'),
|
||||
'move_line_ids': fields.related(
|
||||
'import_transaction_id', 'move_line_ids', string="Move lines",
|
||||
type='many2many', relation='account.move.line'),
|
||||
'move_line_id': fields.related(
|
||||
'import_transaction_id', 'move_line_id', string="Move lines",
|
||||
type='many2one', relation='account.move.line'),
|
||||
'duplicate': fields.related(
|
||||
'import_transaction_id', 'duplicate', string='Flagged as duplicate',
|
||||
type='boolean'),
|
||||
'match_multi': fields.related(
|
||||
'import_transaction_id', 'match_multi',
|
||||
type="boolean", string='Multiple matches'),
|
||||
'match_type': fields.selection(
|
||||
[('manual', 'Manual'), ('move','Move'), ('invoice', 'Invoice'),
|
||||
('payment', 'Payment'), ('payment_order', 'Payment order'),
|
||||
('storno', 'Storno')], 'Match type', readonly=True),
|
||||
'manual_invoice_id': fields.many2one(
|
||||
'account.invoice', 'Match this invoice',
|
||||
domain=[('state', '=', 'open')]),
|
||||
'manual_payment_order_id': fields.many2one(
|
||||
'payment.order', "Payment order to reconcile"),
|
||||
'manual_move_line_id': fields.many2one(
|
||||
'account.move.line', 'Match this entry',
|
||||
domain=[('reconcile_id', '=', False),
|
||||
('account_id.reconcile', '=', True)]
|
||||
),
|
||||
}
|
||||
banking_transaction_wizard()
|
||||
|
||||
class account_bank_statement_line(osv.osv):
|
||||
_inherit = 'account.bank.statement.line'
|
||||
_columns = {
|
||||
@@ -1741,9 +1565,8 @@ class account_bank_statement(osv.osv):
|
||||
for st in self.browse(cr, uid, ids, context=context):
|
||||
if st.state=='draft':
|
||||
continue
|
||||
self.write(cr, uid, [st.id], {'state':'draft'}, context=context)
|
||||
line_obj.cancel(cr, uid, [line.id for line in st.line_ids], context)
|
||||
done.append(st.id)
|
||||
return self.write(cr, uid, done, {'state':'draft'}, context=context)
|
||||
|
||||
_columns = {
|
||||
# override this field *only* to link it to the
|
||||
|
||||
@@ -21,5 +21,6 @@
|
||||
import bank_import
|
||||
import bank_payment_manual
|
||||
import account_payment_order
|
||||
import banking_transaction_wizard
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user