Merge pull request #387 from expsa/purchase_req_chgs

Purchase req chgs
This commit is contained in:
eslam 2024-07-28 07:53:42 +03:00 committed by GitHub
commit b46a95f57c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 1 deletions

View File

@ -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

View File

@ -9,5 +9,10 @@
<field name="number_next">1</field>
<field name="number_increment">1</field>
</record>
<record id="purchase_date_pr_id" model="ir.sequence.date_range">
<field eval="time.strftime('%Y-01-01')" name="date_from"/>
<field eval="time.strftime('%Y-12-31')" name="date_to"/>
<field name="sequence_id" ref="sequence_sr_op"/>
</record>
</data>
</odoo>