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
836 B

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