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.

56 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 CashInvoiceIn(models.TransientModel):
  7. _inherit = 'cash.invoice.in'
  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(CashInvoiceIn, self).default_company(
  13. active_model, active_ids
  14. )
  15. def default_journals(self, active_model, active_ids):
  16. if active_model == 'pos.session':
  17. active = self.env[active_model].browse(active_ids)
  18. if not active.cash_register_id:
  19. raise UserError(_(
  20. "There is no cash register for this Pos session"
  21. ))
  22. return active.cash_register_id.journal_id
  23. return super(CashInvoiceIn, self).default_journals(
  24. active_model, active_ids
  25. )
  26. def default_currency(self, active_model, active_ids):
  27. if active_model == 'pos.session':
  28. journal = self._default_journal()
  29. if journal.currency_id:
  30. return journal.currency_id
  31. return super(CashInvoiceIn, self).default_currency(
  32. active_model, active_ids
  33. )
  34. @api.multi
  35. def run(self):
  36. active_model = self.env.context.get('active_model', False)
  37. active_ids = self.env.context.get('active_ids', False)
  38. if active_model == 'pos.session':
  39. bank_statements = [
  40. session.statement_ids.filtered(
  41. lambda r: r.journal_id.id == self.journal_id.id
  42. )
  43. for session in self.env[active_model].browse(active_ids)
  44. ]
  45. if not bank_statements:
  46. raise UserError(_('Bank Statement was not found'))
  47. return self._run(bank_statements)
  48. else:
  49. return super(CashInvoiceIn, self).run()