Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
560 Visualizzazioni

Hello,

when I create an invoice manually in Odoo interface, the *_ubl_de.xml file is created next to the invoice.

However, when the invoice is created from my custom code where the sale is added, it is not created, only the pdf invoice is created.

How do I handle this in the code so that it is also created? 

In this exampe i use .message_post() method adds only one attachment (pdf) to the message

attachment_ids = request.env['ir.attachment'].sudo().search([

('res_model', 'in', ['account.move', 'mail.compose.message']),

('res_id', '=', invoice.id)

])

_logger.info('/////ATTACHMENT BY INVOICE//////')

_logger.info(attachment_ids)

for attachment in attachment_ids:

attachment.res_model = 'mail.message'

ids_for_email.append(attachment.id)

_logger.info('/////IDS FOR EMAIL//////')

_logger.info(ids_for_email)

invoice.with_context(mail_post_autofollow=True,

lang=partner.lang or request.env.user.lang).message_post(

partner_ids=[partner.id],

body=email_values.get('body_html'),

subject=subject,

subtype_id=request.env.ref('mail.mt_note').id,

model_description=subject,

email_layout_xmlid='mail.mail_notification_light',

attachment_ids=ids_for_email

)


ir_attachment table for this res_id

  id   |       name        |      res_model       | res_id

-------+-------------------+----------------------+--------

37555 | RE3610.pdf        | account.move         |  21446

37554 | RE3610_ubl_de.xml | mail.compose.message |  21446


Logs from this code
/////ATTACHMENT BY INVOICE//////
ir.attachment(37555, 37554)

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
mag 23
2133
2
set 24
11172
0
ott 22
2383
0
mar 22
2
1
nov 19
5625