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.

49 lines
1.5 KiB

  1. # Copyright 2021 ForgeFlow, S.L.
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, fields, models
  4. class ResPartner(models.Model):
  5. _inherit = "res.partner"
  6. is_customer = fields.Boolean(
  7. compute="_compute_is_customer",
  8. inverse="_inverse_is_customer",
  9. store=True,
  10. readonly=False,
  11. string="Is a Customer",
  12. )
  13. is_supplier = fields.Boolean(
  14. compute="_compute_is_supplier",
  15. inverse="_inverse_is_supplier",
  16. store=True,
  17. readonly=False,
  18. string="Is a Supplier",
  19. )
  20. @api.depends("customer_rank")
  21. def _compute_is_customer(self):
  22. for partner in self:
  23. partner.is_customer = bool(partner.customer_rank)
  24. @api.depends("supplier_rank")
  25. def _compute_is_supplier(self):
  26. for partner in self:
  27. partner.is_supplier = bool(partner.supplier_rank)
  28. def _inverse_is_customer(self):
  29. for partner in self:
  30. partners = partner | partner.commercial_partner_id
  31. if partner.is_customer:
  32. partners._increase_rank("customer_rank")
  33. else:
  34. partners.customer_rank = 0
  35. def _inverse_is_supplier(self):
  36. for partner in self:
  37. partners = partner | partner.commercial_partner_id
  38. if partner.is_supplier:
  39. partners._increase_rank("supplier_rank")
  40. else:
  41. partners.supplier_rank = 0