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.

31 lines
927 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 fields, models, api
  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",
  15. compute="_compute_is_loaner",
  16. store=True,
  17. )
  18. @api.multi
  19. @api.depends("loan_line_ids", "loan_line_ids.state")
  20. def _compute_is_loaner(self):
  21. for partner in self:
  22. sudo_partner = partner.sudo()
  23. loans = sudo_partner.loan_line_ids.filtered(
  24. lambda l: l.state in ["subscribed", "waiting", "paid"]
  25. )
  26. sudo_partner.is_loaner = bool(loans)