mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[imp] statement cancel line
This commit is contained in:
@@ -27,7 +27,7 @@ class Statement(orm.Model):
|
|||||||
|
|
||||||
"""Bank Statement.
|
"""Bank Statement.
|
||||||
|
|
||||||
All logic is in the BankStatementLine
|
Minimal changes to allow cancelling single lines.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -38,3 +38,25 @@ class Statement(orm.Model):
|
|||||||
|
|
||||||
_defaults = {
|
_defaults = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def button_confirm_bank(self, cr, uid, ids, context=None):
|
||||||
|
"""Change the state on the statement lines. Return super."""
|
||||||
|
st_line_obj = self.pool['account.bank.statement.line']
|
||||||
|
for st_data in self.read(cr, uid, ids, ['line_ids'], context=context):
|
||||||
|
st_line_obj.write(cr, uid, st_data['line_ids'], {
|
||||||
|
'state': 'confirmed'
|
||||||
|
}, context=context)
|
||||||
|
|
||||||
|
return super(Statement, self).button_confirm_bank(
|
||||||
|
cr, uid, ids, context)
|
||||||
|
|
||||||
|
def button_cancel(self, cr, uid, ids, context=None):
|
||||||
|
"""Change the state on the statement lines. Return super."""
|
||||||
|
st_line_obj = self.pool['account.bank.statement.line']
|
||||||
|
for st_data in self.read(cr, uid, ids, ['line_ids'], context=context):
|
||||||
|
st_line_obj.write(cr, uid, st_data['line_ids'], {
|
||||||
|
'state': 'draft'
|
||||||
|
}, context=context)
|
||||||
|
|
||||||
|
return super(Statement, self).button_cancel(
|
||||||
|
cr, uid, ids, context)
|
||||||
|
|||||||
@@ -52,6 +52,14 @@ class StatementLine(orm.Model):
|
|||||||
the bank-statement-reconcile branch does not).
|
the bank-statement-reconcile branch does not).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if context is None:
|
||||||
|
context = {}
|
||||||
|
local_ctx = context.copy()
|
||||||
|
# if account_constraints is installed, we need to tell it that moves
|
||||||
|
# are being created by a statement, which is OK.
|
||||||
|
# The module tries to prevent direct changes to the moves created by
|
||||||
|
# bank statements.
|
||||||
|
local_ctx['from_parent_object'] = True
|
||||||
statement_pool = self.pool.get('account.bank.statement')
|
statement_pool = self.pool.get('account.bank.statement')
|
||||||
|
|
||||||
for st_line in self.browse(cr, uid, ids, context):
|
for st_line in self.browse(cr, uid, ids, context):
|
||||||
@@ -64,13 +72,15 @@ class StatementLine(orm.Model):
|
|||||||
st_line_number = statement_pool.get_next_st_line_number(
|
st_line_number = statement_pool.get_next_st_line_number(
|
||||||
cr, uid, st_number, st_line, context)
|
cr, uid, st_number, st_line, context)
|
||||||
|
|
||||||
|
# We pass the local_ctx so that account_constraints allows us to
|
||||||
|
# work on the moves generated by the bank statement
|
||||||
statement_pool.create_move_from_st_line(
|
statement_pool.create_move_from_st_line(
|
||||||
cr,
|
cr,
|
||||||
uid,
|
uid,
|
||||||
st_line.id,
|
st_line.id,
|
||||||
curr_id,
|
curr_id,
|
||||||
st_line_number,
|
st_line_number,
|
||||||
context)
|
local_ctx)
|
||||||
self.write(cr, uid, st_line.id, {
|
self.write(cr, uid, st_line.id, {
|
||||||
'state': 'confirmed'
|
'state': 'confirmed'
|
||||||
}, context)
|
}, context)
|
||||||
@@ -83,7 +93,17 @@ class StatementLine(orm.Model):
|
|||||||
module.
|
module.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if context is None:
|
||||||
|
context = {}
|
||||||
|
local_ctx = context.copy()
|
||||||
|
# if account_constraints is installed, we need to tell it that moves
|
||||||
|
# are being created by a statement, which is OK.
|
||||||
|
# The module tries to prevent direct changes to the moves created by
|
||||||
|
# bank statements.
|
||||||
|
local_ctx['from_parent_object'] = True
|
||||||
|
|
||||||
move_pool = self.pool.get('account.move')
|
move_pool = self.pool.get('account.move')
|
||||||
|
|
||||||
set_draft_ids = []
|
set_draft_ids = []
|
||||||
move_unlink_ids = []
|
move_unlink_ids = []
|
||||||
# harvest ids for various actions
|
# harvest ids for various actions
|
||||||
@@ -91,21 +111,23 @@ class StatementLine(orm.Model):
|
|||||||
if st_line.state != 'confirmed':
|
if st_line.state != 'confirmed':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for line in st_line.move_ids:
|
for move in st_line.move_ids:
|
||||||
# We allow for people canceling and removing
|
# We allow for people canceling and removing
|
||||||
# the associated payments, which can lead to confirmed
|
# the associated payments, which can lead to confirmed
|
||||||
# statement lines without an associated move
|
# statement lines without an associated move
|
||||||
move_unlink_ids.append(line.id)
|
move_unlink_ids.append(move.id)
|
||||||
|
# do we need to check that?
|
||||||
|
if move.state != 'draft':
|
||||||
|
raise orm.except_orm(
|
||||||
|
_('Confirmed Journal Entry'),
|
||||||
|
_('You cannot delete a confirmed Statement Line '
|
||||||
|
'associated to a Journal Entry that is posted.'))
|
||||||
set_draft_ids.append(st_line.id)
|
set_draft_ids.append(st_line.id)
|
||||||
|
|
||||||
if st_line.move_line.state != 'draft':
|
|
||||||
raise orm.except_orm(
|
|
||||||
_('Confirmed Journal Entry'),
|
|
||||||
_('You cannot delete a confirmed Statement Line '
|
|
||||||
'associated to a Journal Entry that is posted.'))
|
|
||||||
move_pool.button_cancel(
|
move_pool.button_cancel(
|
||||||
cr, uid, move_unlink_ids, context=context)
|
cr, uid, move_unlink_ids, context=context)
|
||||||
move_pool.unlink(cr, uid, move_unlink_ids, context=context)
|
|
||||||
|
move_pool.unlink(cr, uid, move_unlink_ids, context=local_ctx)
|
||||||
self.write(
|
self.write(
|
||||||
cr, uid, set_draft_ids, {'state': 'draft'}, context=context)
|
cr, uid, set_draft_ids, {'state': 'draft'}, context=context)
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user