-
  In order to test Bank Statement feature of account I create a bank statement line and confirm it and check it's move created
-
  I select the period and journal for the bank statement
-
  !python {model: account.bank.statement}: |
    import time
    journal = self._default_journal_id(cr, uid, {'lang': u'en_US', 'tz': False, 'active_model': 'ir.ui.menu',
      'journal_type': 'bank', 'period_id': time.strftime('%m'), 'active_ids': [ref('menu_bank_statement_tree')], 'active_id': ref('menu_bank_statement_tree')})
    assert journal, 'Journal has not been selected'
-
  I create a bank statement with Opening and Closing balance 0.
-
  !record {model: account.bank.statement, id: account_bank_statement_0}:
    balance_end_real: 0.0
    balance_start: 0.0
    date: !eval time.strftime('%Y-%m-%d')
    journal_id: account.bank_journal
-
  I create bank statement line
-
  !python {model: account.bank.statement.line}: |
    partner = self.onchange_partner_id(cr, uid, [], ref('base.res_partner_4'), context=None)
    vals = {
        'account_id': partner['value']['account_id'],
        'amount': 1000.0,
        'partner_id': ref('base.res_partner_4'),
        'statement_id': ref('account_bank_statement_0'),
        'name': 'EXT001'
    }
    vals.update(partner.get('value',{}))
    line_id = self.create(cr, uid, vals)
    assert line_id, "Account bank statement line has not been created"
-
  I compute bank statement using Compute button
-
  !python {model: account.bank.statement}: |
    self.button_dummy(cr, uid, [ref("account_bank_statement_0")])

-
  I modify the bank statement and set the Closing Balance.
-
  !record {model: account.bank.statement, id: account_bank_statement_0}:
    balance_end_real: 1000.0

-
  I confirm the bank statement using Confirm button
-
  !python {model: account.bank.statement}: |
    self.button_confirm_bank(cr, uid, [ref("account_bank_statement_0")])
-
  I check that bank statement state is now "Closed"
-
  !assert {model: account.bank.statement, id: account_bank_statement_0}:
    - state == 'confirm'

-
  I check that move lines created for bank statement and move state is Posted
-
  !python {model: account.bank.statement}: |
    move_line_obj = self.pool.get('account.move.line')
    bank_data = self.browse(cr, uid, ref("account_bank_statement_0"))
    assert bank_data.move_line_ids, "Move lines not created for bank statement"
    for line in bank_data.move_line_ids:
      assert line.move_id.state == 'posted', "Move state is not posted"
-
  Then I cancel Bank Statements and verifies that it raises a warning
-
  !python {model: account.bank.statement}: |
    from openerp.osv import osv
    try:
      self.button_cancel(cr, uid, [ref("account_bank_statement_0")])
      assert False, "An exception should have been raised, the journal should not let us cancel moves!" 
    except osv.except_osv:
      # exception was raised as expected, as the journal does not allow cancelling moves
      pass
