diff --git a/odex25_purchase/odex25_purchase_coc/models/new_models.py b/odex25_purchase/odex25_purchase_coc/models/new_models.py index db29c4697..b4a91d6cf 100644 --- a/odex25_purchase/odex25_purchase_coc/models/new_models.py +++ b/odex25_purchase/odex25_purchase_coc/models/new_models.py @@ -353,10 +353,17 @@ class PurchaseCoC(models.Model): for rec in self: request = rec.po_id.request_id if request: - if request.employee_id.parent_id.user_id.id != user.id: - raise ValidationError(_('Sorry You are not allowed to Confirm this CoC.')) + if request.employee_id.user_id.id != user.id: + allowed_name = request.employee_id.name + raise ValidationError( + _('Sorry, you are not allowed to Confirm this CoC.\nAllowed user: %s') % allowed_name + ) else: - pass + if rec.po_id.department_id.manager_id.user_id.id != user.id: + allowed_name = rec.po_id.department_id.manager_id.name + raise ValidationError( + _('Sorry, you are not allowed to Confirm this CoC.\nAllowed user: %s') % allowed_name + ) if not any(line.qty_to_receive > 0 for line in rec.coc_line_ids): raise ValidationError(_('You must receive at least one product before confirmation.')) @@ -397,6 +404,21 @@ class PurchaseCoC(models.Model): po = self.po_id.sudo() request = po.request_id + if request: + coach_user = request.employee_id.sudo().coach_id.user_id + allowed_name = coach_user.name + if coach_user.id != user.id: + raise ValidationError( + _('Sorry, you are not allowed to Confirm this CoC.\nAllowed user: %s') % allowed_name + ) + else: + dept_manager = self.po_id.department_id.manager_id.sudo() + coach_user = dept_manager.coach_id.user_id + allowed_name = coach_user.name + if coach_user.id != user.id: + raise ValidationError( + _('Sorry, you are not allowed to Confirm this CoC.\nAllowed user: %s') % allowed_name + ) if not any(line.qty_to_receive > 0 for line in self.coc_line_ids): raise ValidationError(_('You must receive at least one product before approval.'))