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.

41 lines
1.2 KiB

  1. from odoo import api, fields, models
  2. class PurchaseOrder(models.Model):
  3. _inherit = "purchase.order"
  4. # create_uid must mirror the supervisor_id value.
  5. # create_uid is a magic field that belongs to the ORM that is not
  6. # editable via a form.
  7. create_uid = fields.Many2one(
  8. comodel_name="res.users", compute="_compute_create_uid"
  9. )
  10. supervisor_id = fields.Many2one(
  11. comodel_name="res.users",
  12. string="Responsible",
  13. required=True,
  14. default=lambda self: self.env.user,
  15. )
  16. @api.depends("supervisor_id")
  17. def _compute_create_uid(self):
  18. for rec in self:
  19. if rec.supervisor_id:
  20. rec.create_uid = rec.supervisor_id
  21. @api.multi
  22. def write(self, vals):
  23. if "supervisor_id" in vals:
  24. new_partner = (
  25. self.env["res.users"]
  26. .browse(vals["supervisor_id"])
  27. .partner_id.id
  28. )
  29. for rec in self:
  30. rec.message_unsubscribe(
  31. partner_ids=rec.supervisor_id.partner_id.ids
  32. )
  33. rec.message_subscribe(
  34. partner_ids=[new_partner], subtype_ids=[]
  35. )
  36. return super(PurchaseOrder, self).write(vals)