mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[FIX] do not cancel individual lines on statement cancel
[ADD] manual match [FIX] can delete automatic match selection (e.g. invoice) in wizard form
This commit is contained in:
@@ -1330,6 +1330,27 @@ class banking_import_transaction(osv.osv):
|
||||
transaction.payment_order_id):
|
||||
res[transaction.id] = True
|
||||
return res
|
||||
|
||||
def clear_and_write(self, cr, uid, ids, vals=None, context=None):
|
||||
"""
|
||||
Write values in argument 'vals', but clear all match
|
||||
related values first
|
||||
"""
|
||||
write_vals = (dict([(x, False) for x in [
|
||||
'match_type',
|
||||
'move_line_id',
|
||||
'invoice_id',
|
||||
'manual_invoice_id',
|
||||
'manual_move_line_id',
|
||||
'payment_line_id',
|
||||
]] +
|
||||
[(x, [(6, 0, [])]) for x in [
|
||||
'move_line_ids',
|
||||
'invoice_ids',
|
||||
'payment_order_ids',
|
||||
]]))
|
||||
write_vals.update(vals or {})
|
||||
return self.write(cr, uid, ids, write_vals, context=context)
|
||||
|
||||
_columns = {
|
||||
# start mem_bank_transaction atributes
|
||||
@@ -1613,12 +1634,13 @@ class account_bank_statement(osv.osv):
|
||||
""" inject the statement line workflow here """
|
||||
done = []
|
||||
account_move_obj = self.pool.get('account.move')
|
||||
line_obj = self.pool.get('account.bank.statement.line')
|
||||
#line_obj = self.pool.get('account.bank.statement.line')
|
||||
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)
|
||||
# Do not actually cancel all the lines on the statement,
|
||||
# line_obj.cancel(cr, uid, [line.id for line in st.line_ids], context)
|
||||
|
||||
_columns = {
|
||||
# override this field *only* to link it to the
|
||||
|
||||
@@ -71,11 +71,20 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
Implement a trigger to retrieve the corresponding move line
|
||||
when the invoice_id changes
|
||||
"""
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
transaction_obj = self.pool.get('banking.import.transaction')
|
||||
|
||||
# The following fields get never written
|
||||
# they are just triggers for manual matching
|
||||
# which populates regular fields on the transaction
|
||||
manual_invoice_id = vals.pop('manual_invoice_id', False)
|
||||
manual_move_line_id = vals.pop('manual_move_line_id', False)
|
||||
|
||||
res = super(banking_transaction_wizard, self).write(
|
||||
cr, uid, ids, vals, context=context)
|
||||
|
||||
# An invoice is selected from multiple candidates
|
||||
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):
|
||||
@@ -113,6 +122,59 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
_("No entry found for the selected invoice. " +
|
||||
"Try manual reconciliation."))
|
||||
|
||||
if manual_move_line_id or manual_invoice_id:
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
invoice_obj = self.pool.get('account.invoice')
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
for wiz in self.browse(
|
||||
cr, uid, ids, context=context):
|
||||
invoice_ids = False
|
||||
move_line_id = False
|
||||
move_line_ids = False
|
||||
invoice_id = manual_invoice_id
|
||||
if invoice_id:
|
||||
invoice = invoice_obj.browse(
|
||||
cr, uid, manual_invoice_id, context=context)
|
||||
if invoice.move_id:
|
||||
for line in invoice.move_id.line_id:
|
||||
if line.account_id.type in ('receivable', 'payable'):
|
||||
move_line_id = line.id
|
||||
break
|
||||
if not move_line_id:
|
||||
osv.except_osv(
|
||||
_("Cannot select for reconcilion"),
|
||||
_("No entry found for the selected invoice. "))
|
||||
else:
|
||||
move_line_id = manual_move_line_id
|
||||
move_line = move_line_obj.read(
|
||||
cr, uid, move_line_id, ['invoice'], context=context)
|
||||
invoice_id = (move_line['invoice'] and
|
||||
move_line['invoice'][0])
|
||||
vals = {
|
||||
'move_line_id': move_line_id,
|
||||
'move_line_ids': [(6, 0, [move_line_id])],
|
||||
'invoice_id': invoice_id,
|
||||
'invoice_ids': [(6, 0, invoice_id and
|
||||
[invoice_id] or [])],
|
||||
'match_type': 'manual',
|
||||
}
|
||||
transaction_obj.clear_and_write(
|
||||
cr, uid, wiz.import_transaction_id.id,
|
||||
vals, context=context)
|
||||
st_line_vals = {
|
||||
'account_id': move_line_obj.read(
|
||||
cr, uid, move_line_id,
|
||||
['account_id'], context=context)['account_id'][0],
|
||||
}
|
||||
if invoice_id:
|
||||
st_line_vals['partner_id'] = invoice_obj.read(
|
||||
cr, uid, invoice_id,
|
||||
['partner_id'], context=context)['partner_id'][0]
|
||||
statement_line_obj.write(
|
||||
cr, uid, wiz.import_transaction_id.statement_line_id.id,
|
||||
st_line_vals, context=context)
|
||||
return res
|
||||
|
||||
def trigger_write(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Just a button that triggers a write.
|
||||
@@ -120,27 +182,29 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
return True
|
||||
|
||||
def disable_match(self, cr, uid, ids, context=None):
|
||||
vals = (dict([(x, False) for x in [
|
||||
'match_type',
|
||||
'move_line_id',
|
||||
'invoice_id',
|
||||
'manual_invoice_id',
|
||||
'manual_move_line_id',
|
||||
'payment_line_id',
|
||||
]] +
|
||||
[(x, [(6, 0, [])]) for x in [
|
||||
'move_line_ids',
|
||||
'invoice_ids',
|
||||
'payment_order_ids',
|
||||
]]))
|
||||
self.write(cr, uid, ids, vals, context=context)
|
||||
return True
|
||||
"""
|
||||
Clear manual and automatic match information
|
||||
"""
|
||||
if isinstance(ids, (int, float)):
|
||||
ids = [ids]
|
||||
# self.write(cr, uid, ids,
|
||||
# {'manual_invoice_id': False,
|
||||
# 'manual_move_line_id': False,
|
||||
# }, context=context)
|
||||
wizs = self.read(
|
||||
cr, uid, ids, ['import_transaction_id'], context=context)
|
||||
trans_ids = [x['import_transaction_id'][0] for x in wizs
|
||||
if x['import_transaction_id']]
|
||||
return self.pool.get('banking.import.transaction').clear_and_write(
|
||||
cr, uid, trans_ids, context=context)
|
||||
|
||||
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):
|
||||
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)
|
||||
@@ -178,7 +242,7 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
type='many2one', relation='banking.import.transaction'),
|
||||
'residual': fields.related(
|
||||
'import_transaction_id', 'residual', type='float',
|
||||
string='Residual'),
|
||||
string='Residual', readonly=True),
|
||||
'writeoff_account_id': fields.related(
|
||||
'import_transaction_id', 'writeoff_account_id',
|
||||
type='many2one', relation='account.account',
|
||||
@@ -199,10 +263,10 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
'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",
|
||||
'import_transaction_id', 'move_line_ids', string="Entry lines",
|
||||
type='many2many', relation='account.move.line'),
|
||||
'move_line_id': fields.related(
|
||||
'import_transaction_id', 'move_line_id', string="Move lines",
|
||||
'import_transaction_id', 'move_line_id', string="Entry line",
|
||||
type='many2one', relation='account.move.line'),
|
||||
'duplicate': fields.related(
|
||||
'import_transaction_id', 'duplicate', string='Flagged as duplicate',
|
||||
@@ -215,13 +279,13 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
type="char", size=16, string='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"),
|
||||
domain=[('reconciled', '=', False)]),
|
||||
'manual_move_line_id': fields.many2one(
|
||||
'account.move.line', 'Match this entry',
|
||||
domain=[('reconcile_id', '=', False),
|
||||
('account_id.reconcile', '=', True)]
|
||||
'account.move.line', 'Or match this entry',
|
||||
domain=[('account_id.reconcile', '=', True),
|
||||
('reconcile_id', '=', False)],
|
||||
#'manual_payment_order_id': fields.many2one(
|
||||
# 'payment.order', "Payment order to reconcile"),
|
||||
),
|
||||
}
|
||||
banking_transaction_wizard()
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
<group colspan="2" col="2">
|
||||
|
||||
<separator string="System Match" colspan="2"/>
|
||||
<separator string="Current match" colspan="2"/>
|
||||
<field name="match_type"/>
|
||||
<group attrs="{'invisible': [('match_multi', '=', False)]}">
|
||||
<label colspan="2" string="Multiple matches were found for this bank transfer. You must pick one of the matches or select a match manually below." />
|
||||
@@ -40,16 +40,21 @@
|
||||
attrs="{'invisible': [('match_type', 'not in', [('payment', 'storno')])]}"
|
||||
/>
|
||||
<group attrs="{'readonly': [('match_multi', '!=' True)]}">
|
||||
<!-- show if we have an invoice type match (but the user may need to select from multiple options)
|
||||
or whenever there is an invoice_id (e.g. in case of a manual match)
|
||||
-->
|
||||
<field name='invoice_id'
|
||||
attrs="{'invisible': [('match_type', '!=', 'invoice')]}"
|
||||
attrs="{'readonly': [('match_multi', '=', False)], 'invisible': [('match_type', '!=', 'invoice'),('invoice_id', '=', False)]}"
|
||||
domain="[('id', 'in', invoice_ids[0][2])]"
|
||||
/>
|
||||
<!-- show if we have a move type match or a manual match without an invoice_id
|
||||
-->
|
||||
<field name='move_line_id'
|
||||
attrs="{'invisible': [('match_type', '!=', 'move')]}"
|
||||
attrs="{'readonly': [('match_multi', '=', False)], 'invisible': ['|',('match_type', '!=', 'move'),('match_type', '=', 'manual'),('invoice_id', '!=', False)]}"
|
||||
domain="[('id', 'in', move_line_ids[0][2])]"
|
||||
/>
|
||||
<field name='payment_order_id'
|
||||
attrs="{'invisible': [('match_type', '!=', 'payment_order')]}"
|
||||
attrs="{'readonly': [('match_multi', '=', False)], 'invisible': [('match_type', '!=', 'payment_order')]}"
|
||||
domain="[('id', 'in', payment_order_ids[0][2])]"
|
||||
/>
|
||||
</group>
|
||||
@@ -60,6 +65,29 @@
|
||||
string="Select"/>
|
||||
<newline/>
|
||||
|
||||
<!-- residual and write off -->
|
||||
|
||||
<group attrs="{'invisible': [('residual', '=', False)]}" colspan="2" col="2">
|
||||
<separator string="Residual write-off"/>
|
||||
<label string="You must set a write-off account for the residual of this reconciliation" colspan="2"/>
|
||||
<field name="residual"/>
|
||||
<field name="writeoff_account_id"
|
||||
attrs="{'required': [('residual', '!=', False)]}"/>
|
||||
<button colspan="1"
|
||||
name="trigger_write"
|
||||
type="object"
|
||||
string="Set write-off account"/>
|
||||
</group>
|
||||
|
||||
<!-- Redo automatic match -->
|
||||
|
||||
<separator string="System match"/>
|
||||
<label string="You can let the system try to match this bank statement line again after you have made any changes in the database (for instance, add an invoice or a bank account)." colspan="2"/>
|
||||
<newline/>
|
||||
<button colspan="1"
|
||||
name="trigger_match"
|
||||
type="object"
|
||||
string="Match again"/>
|
||||
<!-- Manual selection -->
|
||||
|
||||
<separator string="Manual match" colspan="2"/>
|
||||
@@ -67,34 +95,11 @@
|
||||
<field name="manual_move_line_id"/>
|
||||
<newline/>
|
||||
<button colspan="1"
|
||||
name="match_manual"
|
||||
name="trigger_write"
|
||||
type="object"
|
||||
string="Match"/>
|
||||
</group>
|
||||
|
||||
<!-- residual and write off -->
|
||||
|
||||
<group attrs="{'invisible': [('residual', '=', False)]}" colspan="2" col="2">
|
||||
<separator string="Residual write-off"/>
|
||||
<field name="residual"/><field name="writeoff_account_id"/>
|
||||
<label string="You can set a write-off account for the residual of this reconciliation" colspan="2"/>
|
||||
<button colspan="1"
|
||||
name="trigger_write"
|
||||
type="object"
|
||||
string="Set write-off account"/>
|
||||
</group>
|
||||
|
||||
<!-- Redo automatic match -->
|
||||
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Retry system match"/>
|
||||
<label string="You can let the system try to match this bank statement line again after you have made any changes in the database (for instance, add an invoice or a bank account)." colspan="2"/>
|
||||
<newline/>
|
||||
<button colspan="1"
|
||||
name="trigger_match"
|
||||
type="object"
|
||||
string="Match again"/>
|
||||
</group>
|
||||
<group attrs="{'invisible': [('match_type', '==', False)]}" colspan="2" col="2">
|
||||
<separator string="Disable reconciliation"/>
|
||||
<label string="You can disable the reconciliation of this bank transfer" colspan="2"/>
|
||||
|
||||
Reference in New Issue
Block a user