diff --git a/odex25_purchase/purchase_custom_stock/models/purchase_request.py b/odex25_purchase/purchase_custom_stock/models/purchase_request.py
index 6c04b493b..399358abc 100644
--- a/odex25_purchase/purchase_custom_stock/models/purchase_request.py
+++ b/odex25_purchase/purchase_custom_stock/models/purchase_request.py
@@ -44,7 +44,7 @@ class PurchaseRequest(models.Model):
raise ValidationError(_("Please Select department for employee"))
direct_manager = self.sudo().department_id.manager_id
if direct_manager and direct_manager.user_id and self.env.user.id != direct_manager.user_id.id:
- raise ValidationError(_("You should be The Direct Manager"))
+ raise ValidationError(_("only %s Direct Manager can approve the order"%self.sudo().employee_id.name))
if any(self.line_ids.filtered(lambda line: line.product_id.type == "product")):
self.write({'state': 'warehouse'})
else:
@@ -54,6 +54,7 @@ class PurchaseRequest(models.Model):
+
def create_requisition(self):
"""inherit for take in considiration available qty """
self.is_requisition = True
@@ -211,6 +212,53 @@ class PurchaseRequest(models.Model):
[('product_id', '=', line.product_id.id), ('location_id', '=', rec.location_id.id)],
limit=1).available_quantity
line.qty_purchased=line.qty-line.available_qty
+ def write(self,vals):
+
+ """Ovveride Send Notification On state"""
+ res=super(PurchaseRequest,self).write(vals)
+ if 'state' in vals :
+ if vals['state'] =='direct_manager':
+ direct_manager = self.sudo().department_id.manager_id
+ if direct_manager and direct_manager.user_id:
+ self.message_post(body='Dear %s your approval is required on %s ' % (direct_manager.name, self.name),
+ message_type='notification',
+ author_id=self.env.user.partner_id.id, sticky=True,
+ subtype_id=self.env.ref("mail.mt_comment").id,
+ partner_ids=[direct_manager.user_id.partner_id.id])
+ elif vals['state'] == 'warehouse':
+ stock_group = self.env.ref('stock.group_stock_user')
+ stock_users = self.env['res.users'].search([('groups_id', '=', stock_group.id)])
+ for user in stock_users:
+ stock_employee=self.env['hr.employee'].search([('user_id','=',user.id)],limit=1)
+ if stock_employee and user.partner_id.id:
+ self.message_post(body='Dear %s your approval is required on %s ' % (stock_employee.name, self.name),
+ message_type='notification',
+ author_id=self.env.user.partner_id.id, sticky=True,
+ subtype_id=self.env.ref("mail.mt_comment").id,
+ partner_ids=[user.partner_id.id])
+ elif vals['state'] == 'waiting':
+ purchase_group = self.env.ref('purchase.group_purchase_user')
+ purchase_users = self.env['res.users'].search([('groups_id', '=', purchase_group.id)])
+ for user in purchase_users:
+ purchase_employee = self.env['hr.employee'].search([('user_id', '=', user.id)], limit=1)
+ if purchase_employee and user.partner_id.id:
+ self.message_post(body='Dear %s your approval is required on %s ' % (purchase_employee.name, self.name),
+ message_type='notification',
+ author_id=self.env.user.partner_id.id, sticky=True,
+ subtype_id=self.env.ref("mail.mt_comment").id,
+ partner_ids=[user.partner_id.id])
+ elif vals['state'] == 'employee':
+ print("employee")
+ if self.sudo().employee_id and self.sudo().employee_id.user_id:
+ self.message_post(
+ body='Dear %s please confirm your Delivery on %s ' % (self.sudo().employee_id.name, self.name),
+ message_type='notification',
+ author_id=self.env.user.partner_id.id, sticky=True,
+ subtype_id=self.env.ref("mail.mt_comment").id,
+ partner_ids=[self.sudo().employee_id.user_id.partner_id.id])
+ return res
+
+
diff --git a/odex25_purchase/purchase_requisition_custom/data/purchase_request_seq.xml b/odex25_purchase/purchase_requisition_custom/data/purchase_request_seq.xml
index f348357f6..5a5f6122e 100644
--- a/odex25_purchase/purchase_requisition_custom/data/purchase_request_seq.xml
+++ b/odex25_purchase/purchase_requisition_custom/data/purchase_request_seq.xml
@@ -9,5 +9,10 @@
1
1
+
+
+
+
+