Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
574 Näkymät

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
toukok. 23
2133
2
syysk. 24
11174
0
lokak. 22
2384
0
maalisk. 22
2
1
marrask. 19
5629