Merge pull request #3380 from expsa/dev_odex25_transactions

Dev odex25 transactions
This commit is contained in:
kchyounes19 2025-06-01 15:51:53 +01:00 committed by GitHub
commit b1df39a13a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 35 deletions

View File

@ -22,7 +22,7 @@ class SignLetterTransaction(models.TransientModel):
}) })
# Generate a new attachment (you must have action_generate_attachment() in letters.letters) # Generate a new attachment (you must have action_generate_attachment() in letters.letters)
new_attachment = self.letter_id.action_generate_attachment() new_attachment = self.letter_id.with_context(is_sign=True).action_generate_attachment()
if new_attachment: if new_attachment:
# Set the new attachment as signed # Set the new attachment as signed
attachment_record = self.env['cm.attachment.rule'].browse(new_attachment.id) attachment_record = self.env['cm.attachment.rule'].browse(new_attachment.id)

View File

@ -53,6 +53,7 @@ class Letters(models.Model):
tracking=True tracking=True
) )
job_name = fields.Char(string="Job Name", store=True) job_name = fields.Char(string="Job Name", store=True)
@api.depends('transaction_type', 'name') @api.depends('transaction_type', 'name')
def compute_img(self): def compute_img(self):
employee_id = self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1) employee_id = self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)
@ -119,40 +120,44 @@ class Letters(models.Model):
""" this method called from button action in view xml """ """ this method called from button action in view xml """
# generate pdf from report, use report's id as reference # generate pdf from report, use report's id as reference
for record in self: for record in self:
REPORT_ID = 'exp_transation_letters.report_letter_action_report' if self.env.context.get('is_sign'):
pdf = self.env.ref(REPORT_ID)._render_qweb_pdf(self.ids) employee = self.env['hr.employee'].search([('user_id', '=', self.env.user.id)], limit=1)
# pdf result is a list record.job_name = employee.job_id.name if employee and employee.job_id else ' '
b64_pdf = base64.b64encode(pdf[0]) record.signed_user_id = self.env.user
res_id = '' else:
field_name, res_id = self._get_transaction_values() record.job_name = False
# file_exists = self.env['cm.attachment.rule'].search([(field_name, '=', res_id),('created_from_system','=',True)]) record.signed_user_id = False
# if file_exists: REPORT_ID = 'exp_transation_letters.report_letter_action_report'
# file_exists.unlink() pdf = self.env.ref(REPORT_ID)._render_qweb_pdf(self.ids)
ATTACHMENT_NAME = "Letter" # pdf result is a list
attach_id = self.env['ir.attachment'].create({ b64_pdf = base64.b64encode(pdf[0])
'name': ATTACHMENT_NAME + '.pdf', res_id = ''
'type': 'binary', field_name, res_id = self._get_transaction_values()
'datas': b64_pdf, # file_exists = self.env['cm.attachment.rule'].search([(field_name, '=', res_id),('created_from_system','=',True)])
'res_model': 'cm.attachment.rule', # if file_exists:
'store_fname': ATTACHMENT_NAME, # file_exists.unlink()
'mimetype': 'application/pdf' ATTACHMENT_NAME = "Letter"
}) attach_id = self.env['ir.attachment'].create({
# self.attachment_generated = True 'name': ATTACHMENT_NAME + '.pdf',
employee = self.env['hr.employee'].search([('user_id', '=', attach_id.create_uid.id)], limit=1) 'type': 'binary',
record.job_name = employee.job_id.name if employee and employee.job_id else ' ' 'datas': b64_pdf,
record.signed_user_id = attach_id.create_uid 'res_model': 'cm.attachment.rule',
self.state = 'attached' 'store_fname': ATTACHMENT_NAME,
return self.env['cm.attachment.rule'].sudo().create({ 'mimetype': 'application/pdf'
'employee_id': self.unite.id, })
'entity_id': self.unite.id, # self.attachment_generated = True
'file_save': [(6, 0, attach_id.ids)], self.state = 'attached'
'attachment_filename': ATTACHMENT_NAME, return self.env['cm.attachment.rule'].sudo().create({
field_name: res_id, 'employee_id': self.unite.id,
'date': datetime.datetime.now(), 'entity_id': self.unite.id,
'description': self.name, 'file_save': [(6, 0, attach_id.ids)],
'created_from_system': True, 'attachment_filename': ATTACHMENT_NAME,
# 'signed' : True if self.is_sign else False field_name: res_id,
}) 'date': datetime.datetime.now(),
'description': self.name,
'created_from_system': True,
# 'signed' : True if self.is_sign else False
})
def write(self, values): def write(self, values):
if values.get('content'): if values.get('content'):