fix letter new
This commit is contained in:
parent
a7045a0bfe
commit
7ee9b5cff9
|
|
@ -74,32 +74,38 @@ class Letters(models.Model):
|
||||||
pdf = self.env.ref(REPORT_ID)._render_qweb_pdf(self.ids)
|
pdf = self.env.ref(REPORT_ID)._render_qweb_pdf(self.ids)
|
||||||
# pdf result is a list
|
# pdf result is a list
|
||||||
b64_pdf = base64.b64encode(pdf[0])
|
b64_pdf = base64.b64encode(pdf[0])
|
||||||
res_model = ''
|
|
||||||
res_id = ''
|
res_id = ''
|
||||||
|
field_name = 'internal_transaction_id'
|
||||||
if self.transaction_type == 'internal':
|
if self.transaction_type == 'internal':
|
||||||
transaction = self.env['internal.transaction']
|
|
||||||
res_model = transaction._name
|
|
||||||
res_id = self.internal_transaction_id.id
|
res_id = self.internal_transaction_id.id
|
||||||
|
field_name = 'internal_transaction_id'
|
||||||
elif self.transaction_type == "outgoing":
|
elif self.transaction_type == "outgoing":
|
||||||
transaction = self.env['outgoing.transaction']
|
|
||||||
res_model = transaction._name
|
|
||||||
res_id = self.outgoing_transaction_id.id
|
res_id = self.outgoing_transaction_id.id
|
||||||
|
field_name = 'outgoing_transaction_id'
|
||||||
elif self.transaction_type == "incoming":
|
elif self.transaction_type == "incoming":
|
||||||
transaction = self.env['incoming.transaction']
|
|
||||||
res_model = transaction._name
|
|
||||||
res_id = self.incoming_transaction_id.id
|
res_id = self.incoming_transaction_id.id
|
||||||
# save pdf as attachment
|
field_name = 'incoming_transaction_id'
|
||||||
|
file_exists = self.env['cm.attachment.rule'].search([(field_name, '=', res_id)])
|
||||||
|
if file_exists:
|
||||||
|
file_exists.unlink()
|
||||||
ATTACHMENT_NAME = "Letter"
|
ATTACHMENT_NAME = "Letter"
|
||||||
return self.env['ir.attachment'].create({
|
attach_id = self.env['ir.attachment'].create({
|
||||||
'name': ATTACHMENT_NAME + '.pdf',
|
'name': ATTACHMENT_NAME + '.pdf',
|
||||||
'type': 'binary',
|
'type': 'binary',
|
||||||
'datas': b64_pdf,
|
'datas': b64_pdf,
|
||||||
# 'datas_fname': ATTACHMENT_NAME + '.pdf',
|
|
||||||
'store_fname': ATTACHMENT_NAME,
|
'store_fname': ATTACHMENT_NAME,
|
||||||
'res_model': res_model,
|
|
||||||
'res_id': res_id,
|
|
||||||
'mimetype': 'application/x-pdf'
|
'mimetype': 'application/x-pdf'
|
||||||
})
|
})
|
||||||
|
return self.env['cm.attachment.rule'].sudo().create({
|
||||||
|
'employee_id': self.unite.id,
|
||||||
|
'entity_id': self.unite.id,
|
||||||
|
'file_save': [(6, 0, attach_id.ids)] ,
|
||||||
|
'attachment_filename': ATTACHMENT_NAME,
|
||||||
|
field_name:res_id,
|
||||||
|
'date': datetime.datetime.now(),
|
||||||
|
'description': self.name,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def write(self, values):
|
def write(self, values):
|
||||||
if values.get('content'):
|
if values.get('content'):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue