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.

29 lines
910 B

  1. # Copyright 2019 Coop IT Easy SCRL fs
  2. # Houssine BAKKALI <houssine@coopiteasy.be>
  3. # Robin Keunen <robin@coopiteasy.be>
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from odoo import api, fields, models
  6. class ResPartner(models.Model):
  7. _inherit = "res.partner"
  8. loan_line_ids = fields.One2many(
  9. comodel_name="loan.issue.line",
  10. inverse_name="partner_id",
  11. string="Loans",
  12. )
  13. is_loaner = fields.Boolean(
  14. string="Loaner", compute="_compute_is_loaner", store=True
  15. )
  16. @api.multi
  17. @api.depends("loan_line_ids", "loan_line_ids.state")
  18. def _compute_is_loaner(self):
  19. for partner in self:
  20. sudo_partner = partner.sudo()
  21. loans = sudo_partner.loan_line_ids.filtered(
  22. lambda l: l.state in ["subscribed", "waiting", "paid"]
  23. )
  24. sudo_partner.is_loaner = bool(loans)