You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2017 Creu Blanca
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from odoo import api, models, _
  5. from odoo.exceptions import UserError
  6. class CashInvoiceOut(models.TransientModel):
  7. _inherit = 'cash.invoice.out'
  8. def default_company(self, active_model, active_ids):
  9. if active_model == 'pos.session':
  10. active = self.env[active_model].browse(active_ids)
  11. return active[0].config_id.company_id
  12. return super(CashInvoiceOut, self).default_company(
  13. active_model, active_ids
  14. )
  15. def default_currency(self, active_model, active_ids):
  16. if active_model == 'pos.session':
  17. journal = self._default_journal()
  18. if journal.currency_id:
  19. return journal.currency_id
  20. return super(CashInvoiceOut, self).default_currency(
  21. active_model, active_ids
  22. )
  23. def default_journals(self, active_model, active_ids):
  24. if active_model == 'pos.session':
  25. active = self.env[active_model].browse(active_ids)
  26. return self.env['account.journal'].browse(
  27. [r.journal_id.id for r in active.statement_ids])
  28. return super(CashInvoiceOut, self).default_journals(
  29. active_model, active_ids
  30. )
  31. @api.multi
  32. def run(self):
  33. active_model = self.env.context.get('active_model', False)
  34. active_ids = self.env.context.get('active_ids', False)
  35. if active_model == 'pos.session':
  36. bank_statements = [
  37. session.statement_ids.filtered(
  38. lambda r: r.journal_id.id == self.journal_id.id
  39. )
  40. for session in self.env[active_model].browse(active_ids)
  41. ]
  42. if not bank_statements:
  43. raise UserError(_('Bank Statement was not found'))
  44. return self._run(bank_statements)
  45. else:
  46. return super(CashInvoiceOut, self).run()