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.

38 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',
  9. compute='_compute_create_uid',
  10. )
  11. supervisor_id = fields.Many2one(
  12. comodel_name='res.users',
  13. string='Responsible',
  14. required=True,
  15. default=lambda self: self.env.user,
  16. )
  17. @api.depends('supervisor_id')
  18. def _compute_create_uid(self):
  19. for rec in self:
  20. if rec.supervisor_id:
  21. rec.create_uid = rec.supervisor_id
  22. @api.multi
  23. def write(self, vals):
  24. if 'supervisor_id' in vals:
  25. new_supervisor = vals['supervisor_id']
  26. for rec in self:
  27. rec.message_unsubscribe_users(
  28. user_ids=rec.supervisor_id.ids,
  29. )
  30. rec.message_subscribe_users(
  31. user_ids=[new_supervisor],
  32. subtype_ids=[],
  33. )
  34. return super(PurchaseOrder, self).write(vals)