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.

52 lines
1.9 KiB

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