[FIX] hr: singleton error on writing user to employee

before this commit, on writing user_id to hr.employee
on multiple record in raisng single ton error.

after this commit, no error wont be raised on the
same.

closes odoo/odoo#130650

X-original-commit: ebc686b8abc84538f224ff4db205ce1231b747c3
Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com>
This commit is contained in:
niyasraphy
2023-08-03 19:31:40 +02:00
committed by sofiagvaladze
parent 59828459ad
commit 68630aaf65
+9 -8
View File
@@ -393,20 +393,21 @@ class HrEmployeePrivate(models.Model):
def write(self, vals):
if 'work_contact_id' in vals:
account_id = vals.get('bank_account_id') or self.bank_account_id.id
if account_id:
bank_account = self.env['res.partner.bank'].browse(account_id)
if vals['work_contact_id'] != bank_account.partner_id.id:
if bank_account.allow_out_payment:
bank_account.sudo().allow_out_payment = False
bank_account.partner_id = vals['work_contact_id']
account_ids = vals.get('bank_account_id') or self.bank_account_id.ids
if account_ids:
bank_accounts = self.env['res.partner.bank'].browse(account_ids)
for bank_account in bank_accounts:
if vals['work_contact_id'] != bank_account.partner_id.id:
if bank_account.allow_out_payment:
bank_account.sudo().allow_out_payment = False
bank_account.partner_id = vals['work_contact_id']
self.message_unsubscribe(self.work_contact_id.ids)
if vals['work_contact_id']:
self._message_subscribe([vals['work_contact_id']])
if 'user_id' in vals:
# Update the profile pictures with user, except if provided
vals.update(self._sync_user(self.env['res.users'].browse(vals['user_id']),
(bool(self.image_1920))))
(bool(all(emp.image_1920 for emp in self)))))
if 'work_permit_expiration_date' in vals:
vals['work_permit_scheduled_activity'] = False
res = super(HrEmployeePrivate, self).write(vals)