res_bank_payment.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request
  3. from res_bank_payment_type import get_bank_payment_types
  4. from server_datetime import get_date
  5. _MODEL = 'res.bank.payments'
  6. '''
  7. '''
  8. def create_bank_payment_statement(data, invoice_id, account_voucher_id):
  9. invoice = request.env['account.invoice'].browse(invoice_id)
  10. account_voucher = request.env['account.voucher'].browse(account_voucher_id)
  11. bank_statement_line = request.env['account.bank.statement.line'].search([('voucher_id', '=', account_voucher_id)])
  12. bank_payments_type_id = request.env['res.bank.payments.type'].get_bank_payments_type_id(account_voucher.journal_id.id)
  13. values = {
  14. 'bank_payments_type_id': bank_payments_type_id,
  15. 'bank_id': data.get('bank_id', None),
  16. 'currency_id': invoice.currency_id.id,
  17. 'date': invoice.date_invoice,
  18. 'customer_id': invoice.partner_id.id,
  19. 'number_cta': data.get('number_cta', None),
  20. 'number_cta_origin': data.get('number_cta_origin', None),
  21. 'name_holder': data.get('name_holder', None),
  22. 'number': data.get('number'),
  23. 'date_maturity': data.get('date_maturity', '') or get_date(),
  24. 'amount_total': data.get('amount', None),
  25. 'payments_line': [[0, False, {
  26. 'amount': abs(account_voucher.amount),
  27. 'amount_currency': 0.0,
  28. 'date': invoice.date_invoice,
  29. 'statement_line_id': bank_statement_line.id,
  30. 'statement_id': bank_statement_line.statement_id.id,
  31. 'type_operation': ('payment', 'receipt')[invoice.type == 'out_invoice'],
  32. 'currency_id': invoice.currency_id.id
  33. }]]
  34. }
  35. request.env['res.bank.payments'].create(values)