Update forward_trasaction.py
This commit is contained in:
parent
a8e4247c7d
commit
9abefd6b0f
|
|
@ -20,31 +20,43 @@ class ForwardTransactionWizard(models.TransientModel):
|
||||||
elif self.outgoing_transaction_id:
|
elif self.outgoing_transaction_id:
|
||||||
transaction = self.outgoing_transaction_id
|
transaction = self.outgoing_transaction_id
|
||||||
name = 'outgoing_transaction_id'
|
name = 'outgoing_transaction_id'
|
||||||
forward_user_id = self.employee.user_id
|
|
||||||
|
forward_user_id = self.employee.user_id.id
|
||||||
if self.forward_type != 'employee':
|
if self.forward_type != 'employee':
|
||||||
forward_user_id = self.internal_unit.secretary_id.user_id.id
|
forward_user_id = self.internal_unit.secretary_id.user_id.id
|
||||||
to_id = self.internal_unit.secretary_id.id
|
to_id = self.internal_unit.secretary_id.id
|
||||||
unit_id = self.internal_unit.id
|
unit_id = self.internal_unit.id
|
||||||
|
|
||||||
transaction.forward_user_id = forward_user_id
|
transaction.forward_user_id = forward_user_id
|
||||||
|
|
||||||
leave_employee = transaction.get_employee_leave(to_id, unit_id, date.today())
|
leave_employee = transaction.get_employee_leave(to_id, unit_id, date.today())
|
||||||
if leave_employee:
|
if leave_employee:
|
||||||
forward_user_id = self.env['cm.entity'].search([('id', '=', leave_employee)]).user_id.id
|
forward_user_id = self.env['cm.entity'].search([('id', '=', leave_employee)]).user_id.id
|
||||||
to_id = leave_employee
|
to_id = leave_employee
|
||||||
transaction.forward_user_id = forward_user_id
|
transaction.forward_user_id = forward_user_id
|
||||||
|
|
||||||
transaction.last_forwarded_user = self.env.uid
|
transaction.last_forwarded_user = self.env.uid
|
||||||
|
|
||||||
if self.is_secret:
|
if self.is_secret:
|
||||||
transaction.secret_reason = self.secret_reason
|
transaction.secret_reason = self.secret_reason
|
||||||
transaction.secret_forward_user = self.env['cm.entity'].search([('user_id', '=', forward_user_id.id)], limit=1)
|
transaction.secret_forward_user = self.env['cm.entity'].search([('user_id', '=', forward_user_id)], limit=1)
|
||||||
|
|
||||||
employee = transaction.current_employee()
|
employee = transaction.current_employee()
|
||||||
from_id = self.env['cm.entity'].search([('user_id', '=', self.env.uid)], limit=1)
|
from_id = self.env['cm.entity'].search([('user_id', '=', self.env.uid)], limit=1)
|
||||||
|
|
||||||
transaction.is_forward = True
|
transaction.is_forward = True
|
||||||
|
|
||||||
|
# Handle attachment rule
|
||||||
if self.forward_attachment_id:
|
if self.forward_attachment_id:
|
||||||
|
attachment = self.env['ir.attachment'].browse(self.forward_attachment_id.id)
|
||||||
transaction.attachment_rule_ids.create({
|
transaction.attachment_rule_ids.create({
|
||||||
'file_save': self.forward_attachment_id,
|
'file_save': attachment.datas, # Ensure this is binary data
|
||||||
'name': transaction.id,
|
'name': transaction.id,
|
||||||
'description': self.att_description,
|
'description': self.att_description,
|
||||||
'attachment_filename': self.filename,
|
'attachment_filename': attachment.name,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Create trace record
|
||||||
transaction.trace_ids.create({
|
transaction.trace_ids.create({
|
||||||
'action': 'forward',
|
'action': 'forward',
|
||||||
'to_id': to_id,
|
'to_id': to_id,
|
||||||
|
|
@ -54,19 +66,23 @@ class ForwardTransactionWizard(models.TransientModel):
|
||||||
'cc_ids': [(6, 0, self.cc_ids.ids)],
|
'cc_ids': [(6, 0, self.cc_ids.ids)],
|
||||||
name: transaction.id
|
name: transaction.id
|
||||||
})
|
})
|
||||||
|
|
||||||
if self.internal_transaction_id or self.incoming_transaction_id:
|
if self.internal_transaction_id or self.incoming_transaction_id:
|
||||||
transaction.action_send_forward()
|
transaction.action_send_forward()
|
||||||
'''for notification partner in cc or forward user'''
|
|
||||||
|
# Notification
|
||||||
target = self.forward_type
|
target = self.forward_type
|
||||||
target_name = target == 'employee' and self.employee.name or self.internal_unit.name
|
target_name = target == 'employee' and self.employee.name or self.internal_unit.name
|
||||||
subj = _('Message Has been forwarded !')
|
subj = _('Message Has been forwarded !')
|
||||||
msg = _(u'{} ← {}').format(
|
msg = _(u'{} ← {}').format(
|
||||||
employee and employee.name or '#', target_name)
|
employee and employee.name or '#', target_name)
|
||||||
msg = u'{}<br /><b>{}</b> {}.<br />{}'.format(msg,
|
msg = u'{}<br /><b>{}</b> {}.<br />{}'.format(
|
||||||
_(u'Action Taken'), self.procedure_id.name,
|
msg,
|
||||||
u'<a href="%s" >رابط المعاملة</a> ' % (
|
_(u'Action Taken'), self.procedure_id.name,
|
||||||
transaction.get_url()))
|
u'<a href="%s" >رابط المعاملة</a> ' % (transaction.get_url())
|
||||||
# add mail notification
|
)
|
||||||
|
|
||||||
|
# Add mail notification
|
||||||
partner_ids = []
|
partner_ids = []
|
||||||
if self.forward_type == 'unit':
|
if self.forward_type == 'unit':
|
||||||
partner_ids.append(self.internal_unit.secretary_id.user_id.partner_id.id)
|
partner_ids.append(self.internal_unit.secretary_id.user_id.partner_id.id)
|
||||||
|
|
@ -77,7 +93,9 @@ class ForwardTransactionWizard(models.TransientModel):
|
||||||
partner_ids.append(partner.secretary_id.user_id.partner_id.id)
|
partner_ids.append(partner.secretary_id.user_id.partner_id.id)
|
||||||
elif partner.type == 'employee':
|
elif partner.type == 'employee':
|
||||||
partner_ids.append(partner.user_id.partner_id.id)
|
partner_ids.append(partner.user_id.partner_id.id)
|
||||||
|
|
||||||
transaction.action_send_notification(subj, msg, partner_ids)
|
transaction.action_send_notification(subj, msg, partner_ids)
|
||||||
|
|
||||||
if self.incoming_transaction_id:
|
if self.incoming_transaction_id:
|
||||||
if transaction.state == 'draft':
|
if transaction.state == 'draft':
|
||||||
transaction.state = 'send'
|
transaction.state = 'send'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue