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

from odoo import api, fields, models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
# create_uid must mirror the supervisor_id value.
# create_uid is a magic field that belongs to the ORM that is not
# editable via a form.
create_uid = fields.Many2one(
comodel_name="res.users", compute="_compute_create_uid"
)
supervisor_id = fields.Many2one(
comodel_name="res.users",
string="Responsible",
required=True,
default=lambda self: self.env.user,
)
@api.depends("supervisor_id")
def _compute_create_uid(self):
for rec in self:
if rec.supervisor_id:
rec.create_uid = rec.supervisor_id
@api.multi
def write(self, vals):
if "supervisor_id" in vals:
new_partner = (
self.env["res.users"]
.browse(vals["supervisor_id"])
.partner_id.id
)
for rec in self:
rec.message_unsubscribe(
partner_ids=rec.supervisor_id.partner_id.ids
)
rec.message_subscribe(
partner_ids=[new_partner], subtype_ids=[]
)
return super(PurchaseOrder, self).write(vals)