[imp] statement cancel line

This commit is contained in:
Leonardo Pistone
2014-01-23 11:51:55 +01:00
parent f76a7f4c30
commit eabbb3b8d4
2 changed files with 54 additions and 10 deletions

View File

@@ -27,7 +27,7 @@ class Statement(orm.Model):
"""Bank Statement.
All logic is in the BankStatementLine
Minimal changes to allow cancelling single lines.
"""
@@ -38,3 +38,25 @@ class Statement(orm.Model):
_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)

View File

@@ -52,6 +52,14 @@ class StatementLine(orm.Model):
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')
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(
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(
cr,
uid,
st_line.id,
curr_id,
st_line_number,
context)
local_ctx)
self.write(cr, uid, st_line.id, {
'state': 'confirmed'
}, context)
@@ -83,7 +93,17 @@ class StatementLine(orm.Model):
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')
set_draft_ids = []
move_unlink_ids = []
# harvest ids for various actions
@@ -91,21 +111,23 @@ class StatementLine(orm.Model):
if st_line.state != 'confirmed':
continue
for line in st_line.move_ids:
for move in st_line.move_ids:
# We allow for people canceling and removing
# the associated payments, which can lead to confirmed
# 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)
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(
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(
cr, uid, set_draft_ids, {'state': 'draft'}, context=context)
return True