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.

39 lines
1.4 KiB

  1. # Copyright (C) 2019-Today: GTRAP (<http://www.grap.coop/>)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models
  5. class PosSession(models.Model):
  6. _inherit = 'pos.session'
  7. display_move_reason_income = fields.Boolean(
  8. compute='_compute_display_move_reason')
  9. display_move_reason_expense = fields.Boolean(
  10. compute='_compute_display_move_reason')
  11. @api.multi
  12. def _compute_display_move_reason(self):
  13. MoveReason = self.env['pos.move.reason']
  14. for session in self:
  15. # Get all reasons
  16. reasons = MoveReason.search([
  17. ('company_id', '=', session.config_id.company_id.id)])
  18. session.display_move_reason_income = len(
  19. reasons.filtered(lambda x: x.is_income_reason))
  20. session.display_move_reason_expense = len(
  21. reasons.filtered(lambda x: x.is_expense_reason))
  22. def button_move_income(self):
  23. return self._button_move_reason('income')
  24. def button_move_expense(self):
  25. return self._button_move_reason('expense')
  26. def _button_move_reason(self, move_type):
  27. action = self.env.ref(
  28. 'pos_cash_move_reason.action_wizard_pos_move_reason').read()[0]
  29. action['context'] = {'default_move_type': move_type}
  30. return action