account_bank_statement.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. import time
  3. from openerp.osv import fields, osv
  4. from openerp.tools import float_compare
  5. from openerp.tools.translate import _
  6. import openerp.addons.decimal_precision as dp
  7. class AccountBankStatement(osv.osv):
  8. _inherit = "account.bank.statement"
  9. def button_confirm_cash(self, cr, uid, ids, context=None):
  10. absl_proxy = self.pool.get('account.bank.statement.line')
  11. TABLES = ((_('Profit'), 'profit_account_id'), (_('Loss'), 'loss_account_id'),)
  12. for obj in self.browse(cr, uid, ids, context=context):
  13. obj.difference = 0.0
  14. if obj.difference == 0.0:
  15. continue
  16. elif obj.difference < 0.0:
  17. account = obj.journal_id.loss_account_id
  18. name = _('Loss')
  19. if not obj.journal_id.loss_account_id:
  20. raise osv.except_osv(_('Error!'), _('There is no Loss Account on the journal %s.') % (obj.journal_id.name,))
  21. else: # obj.difference > 0.0
  22. account = obj.journal_id.profit_account_id
  23. name = _('Profit')
  24. if not obj.journal_id.profit_account_id:
  25. raise osv.except_osv(_('Error!'), _('There is no Profit Account on the journal %s.') % (obj.journal_id.name,))
  26. values = {
  27. 'statement_id' : obj.id,
  28. 'journal_id' : obj.journal_id.id,
  29. 'account_id' : account.id,
  30. 'amount' : obj.difference,
  31. 'name' : name,
  32. }
  33. absl_proxy.create(cr, uid, values, context=context)
  34. return super(AccountBankStatement, self).button_confirm_bank(cr, uid, ids, context=context)