Hello,
I am customizing account.invoice in Tryton and I generate an XML file as a binary field:
invoice_xrechnung
invoice_xrechnung_filename
My problem is that when I open the email wizard, so the XRechnung is not automatically selected in the attachements field. at now after generate the file i can find it in attachements directly but not selected automatically , when I open the email composer and that what I want is to be selected automatically without let me everytime select the file when I want to send email
again for more clarity, What I want is:
when I open the email compose window from an invoice,
the generated XML File should appear selected by default in the attachments or files area,
without the user needing to choose it manually in attachements.
I would like to know How i can make generated file to be by default selected on attachements field without select it by my self
This is my code now:
class Invoice(metaclass=PoolMeta):
name = ‘account.invoice’
invoice_xrechnung = fields.Binary(‘XRechnung’,
filename=‘invoice_xrechnung_filename’)
invoice_xrechnung_filename = fields.Function(fields.Char(
‘XRechnung filename’), ‘get_invoice_xrechnung_filename’)
def generate_xrechnung(self):
pool = Pool()
Configuration = pool.get('account.configuration')
Invoice = pool.get('account.invoice')
config = Configuration(1)
transaction = Transaction()
if self.invoice_xrechnung:
self.attach_xrechnung()
def attach_xrechnung(self):
if self.invoice_xrechnung:
Attachment = Pool().get('ir.attachment')
existing = Attachment.search([
('resource', '=', '%s,%s' % (self.__name__, self.id)),
('name', '=', self.invoice_xrechnung_filename),
])
if existing:
print(f"[DEBUG] Attachment already exists for invoice {self.rec_name}")
else:
Attachment.create([{
'name': self.invoice_xrechnung_filename,
'data': self.invoice_xrechnung,
'resource': '%s,%s' % (self.__name__, self.id),
'type': 'data',
}])
print(f"[DEBUG] Attachment created: {self.invoice_xrechnung_filename}")
Is it feasible to do that??
