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.

58 lines
2.2 KiB

  1. # Copyright 2019 Open Source Integrators
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import api, models
  4. class TierValidation(models.AbstractModel):
  5. _inherit = "tier.validation"
  6. @api.model
  7. def _get_under_validation_exceptions(self):
  8. """Extend for more field exceptions."""
  9. res = super(TierValidation, self)._get_under_validation_exceptions() or []
  10. ex_fields = ["categ_id", "state", "customer", "supplier", "excise_tax"]
  11. for val in ex_fields:
  12. res.append(val)
  13. return res
  14. def validate_tier(self):
  15. super(TierValidation, self).validate_tier()
  16. # make sure to only work with res.partner object.
  17. if self._name != "res.partner":
  18. return
  19. for partner in self:
  20. rec = self.env["tier.review"].search(
  21. [("res_id", "=", partner.id), ("model", "=", "res.partner")]
  22. )
  23. if rec and rec.status == "approved":
  24. partner.state = "approved"
  25. # Need to override for Partner Tier Validation since can_review field
  26. # is set to True based only
  27. # if current user is a member of reviewer_ids. This can_review field
  28. # is used to enable or disable the boolean
  29. # field Is Customer / Is Vendor not only during the Validation process
  30. # but even if it is in Approved State.
  31. @api.depends("review_ids")
  32. def _compute_reviewer_ids(self):
  33. if str(self.__class__) == "<class 'odoo.api.res.partner'>":
  34. for rec in self:
  35. rec.reviewer_ids = rec.review_ids.filtered(
  36. lambda r: r.status in ("pending", "approved")
  37. ).mapped("reviewer_ids")
  38. else:
  39. for rec in self:
  40. rec.reviewer_ids = rec.review_ids.filtered(
  41. lambda r: r.status == "pending"
  42. ).mapped("reviewer_ids")
  43. def request_validation(self):
  44. res = super().request_validation()
  45. for rec in self.filtered(lambda x: x._name == "res.partner"):
  46. rec.message_subscribe(
  47. partner_ids=[
  48. self.env.user.partner_id.id,
  49. ]
  50. )
  51. return res