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