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.

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