1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- # -*- coding: utf-8 -*-
- from openerp.http import request
- _MODEL = 'account.bank.statement'
- '''
- Create account bank statement lines
- '''
- def create_bank_statement_lines(account_voucher_id, reference=None):
- account_voucher = request.env['account.voucher'].browse(account_voucher_id)
- return [[0, False, {
- 'name': account_voucher.reference,
- 'amount': account_voucher.amount,
- 'partner_id': account_voucher.partner_id.id,
- 'voucher_id': account_voucher.id,
- 'journal_id': account_voucher.journal_id.id,
- 'account_id': account_voucher.account_id.id,
- 'journal_entry_id': account_voucher.move_id.id,
- 'currency_id': account_voucher.currency_id.id,
- 'ref': 'POS/' + (reference or '')
- }]]
- '''
- Create account bank statement
- '''
- def create_bank_statement(account_voucher_id, date_today):
- account_voucher = request.env['account.voucher'].browse(account_voucher_id)
- domain = [
- ('journal_id', '=', account_voucher.journal_id.id),
- ('date', '=', date_today)
- ]
- account_bank_statement = request.env[_MODEL].search(domain)
- account_bank_statement_lines = create_bank_statement_lines(account_voucher_id)
- account_bank_statement_values = {
- 'date': date_today,
- 'user_id': request.env.user.id,
- 'journal_id': account_voucher.journal_id.id,
- 'period_id': account_voucher.period_id.id,
- 'line_ids': account_bank_statement_lines,
- 'state': 'open' if account_voucher.journal_id.type == 'cash' else 'draft'
- }
- if account_bank_statement:
- size = len(account_bank_statement)
- if size == 1:
- account_bank_statement.write(account_bank_statement_values)
- else:
- account_bank_statement[size - 1].write(account_bank_statement_values)
- else:
- account_bank_statement.create(account_bank_statement_values)
- return account_bank_statement
|