İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
6370 Görünümler

Please help on this issue, thanks in advance!

A) What I am looking for: 

div 'o_attachment_preview' should change the preview if invoice property is changed or the format is changed.

B) the issue with 'o_attachment_preview'
1) in Odoo 13

2) I am using div 'o_attachment_preview' to show up the Invoice preview on the right side of Invoice page  and  it shows  up  correctly,  like below:

3) the problem is that when I update the Invoice format or update the Invoice property, like changing as another customer, the preview only shows previous content, rather than new invoice.



Avatar
Vazgeç
Üretici En İyi Yanıt

I finally figured it out that if we are going to make it as I expect by code, a bug must be fixed and an odoo's behavior should be changed. Hope this helps if anyone wants it.

1) current behavior:

- when to print report, odoo creates the pdf file as an attachment in the invoice chatting widget only when there is no such attachment; it will not attach it if there has been one there;

- in the widget "o_attachment_preview", 'order' does NOT work as expected because the  file created first is always selected.



2) analysis:

As a   matter of fact, 'order' works but there is another property "is_main" of each attachment in the invoice attachment list blocks the first attachment file to be selected, as a result, 'order' does NOT work eventually ;

3) solution to update preview every time when to print a new  invoice:

a) fix bug in "o_attachment_preview"

if (options.order === 'desc') {

attachments.reverse ();

} if (attachments.length> 0) {---> add code to  enable the first file in order to be selected attachments [0] .is_main = True; }







b) update design of creating attachment: remove the existing attachment and then create new one to replace it (which will be selected by "o_attachment_preview")

- addons \ snailmail \ models \ snailmail_letter.py

def _fetch_attachment (self): if self. attachment_id: self.attachment_id.unlink () ---> remove the existing attachment # create new attachment file as it does






Avatar
Vazgeç
En İyi Yanıt

class AccountMoves(models.Model): _inherit = 'account.move'
def update_invoice_pdf(self): pdf = request.env['ir.actions.report'].sudo()._render_qweb_pdf('account.report_invoice_with_payments', [self.id]) self.invoice_pdf_report_file = base64.b64encode(pdf[0])



this seems to work in odoo17

Avatar
Vazgeç
En İyi Yanıt

You have to run the  register_as_main_attachment() method to PDF attachment.

This will indicate that PDF attachment is the one to be in o_attachment_preview div.
(probed in Odoo 13 and 16)

Ex:

pdf = self.env['ir.attachment'].create(attachment_values)
pdf.register_as_main_attachment()



Avatar
Vazgeç
En İyi Yanıt

Hi,

The invoice attachment is by default has a property called 'Reload From Attachment' enabled. So the PDF will be always reloaded from the attachment. So you have to delete the existing attachment PDF after changing the properties or data and click on 'Send & Print' button again to get the attachment with updated data.

Regards

Avatar
Vazgeç
Üretici

Thanks for your explanation! I appreciate your help!

Do you have ideas about how to do it by code, rather than manual actions? It seems that "delete the existing PDF attachment after changing the properties or data and click on 'Send & Print' button" is done manually.