diff --git a/odex25_transactions/exp_transaction_documents/wizard/transaction_reply_wizard.py b/odex25_transactions/exp_transaction_documents/wizard/transaction_reply_wizard.py index a624e5592..a96de05d8 100644 --- a/odex25_transactions/exp_transaction_documents/wizard/transaction_reply_wizard.py +++ b/odex25_transactions/exp_transaction_documents/wizard/transaction_reply_wizard.py @@ -40,19 +40,21 @@ class TransactionReturnWizard(models.TransientModel): transaction.forward_user_id = transaction.employee_id.user_id.id transaction.state = 'reply' forward_entity = self.env['cm.entity'].search([('user_id', '=', transaction.forward_user_id.id)],limit=1) - attachment = self.env['ir.attachment'].create({ - 'name': self.filename, - 'datas': self.attachment_id, - 'type': 'binary', - 'res_model': 'cm.attachment.rule', - 'res_id': transaction.id, - }) - transaction.attachment_rule_ids.create({ - 'file_save': [(4, attachment.id)], - # 'name': transaction.id, - 'description': self.att_description, - 'attachment_filename': self.filename, - }) + # Check if attachment_id and filename are not empty before creating attachment + if self.attachment_id and self.filename: + attachment = self.env['ir.attachment'].create({ + 'name': self.filename, + 'datas': self.attachment_id, + 'type': 'binary', + 'res_model': 'cm.attachment.rule', + 'res_id': transaction.id, + }) + transaction.attachment_rule_ids.create({ + 'file_save': [(4, attachment.id)], + # 'name': transaction.id, + 'description': self.att_description, + 'attachment_filename': self.filename, + }) transaction.trace_ids.create({ 'action': 'reply',