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.

33 lines
1003 B

  1. # Copyright 2016 Antonio Espinosa
  2. # Copyright 2020 Tecnativa - João Marques
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import fields, models
  5. class ResCompany(models.Model):
  6. _inherit = "res.company"
  7. partner_ref_unique = fields.Selection(
  8. selection=[
  9. ("none", "None"),
  10. ("companies", "Only companies"),
  11. ("all", "All partners"),
  12. ],
  13. string="Unique partner reference for",
  14. default="none",
  15. )
  16. def write(self, vals):
  17. """Launch manually the constraint check in partners as current ORM
  18. doesn't trigger the constraint on related fields.
  19. """
  20. res = super().write(vals)
  21. if "partner_ref_unique" in vals:
  22. partners = (
  23. self.env["res.partner"]
  24. .with_context(active_test=False)
  25. .search([("company_id", "in", [False] + self.ids)])
  26. )
  27. partners._check_ref()
  28. return res