diff options
| author | Adrien Widart <awt@odoo.com> | 2021-02-01 09:11:18 +0000 |
|---|---|---|
| committer | Adrien Widart <awt@odoo.com> | 2021-02-17 07:15:53 +0000 |
| commit | 643e7b06aee2a91190a3a7271211e70e4888d595 (patch) | |
| tree | ed6ec0e41afc6fd4790319340446c44448356649 /addons/account/models/ir_actions_report.py | |
| parent | 0ad1c1631eb233b3e8f98b40f8c0813d0ad7acbe (diff) | |
[FIX] account: set printed invoice as main attachment
When printing some invoices, they are not registered as main
attachment. Therefore, when sending a follow-up report, a UserError
message asks the user to print the invoices first.
To reproduce the error:
(Need account_accountant, use demo data)
1. Go to Accounting > Configuration > Invoicing > Follow-up Levels
2. Select "First Reminder Email"
3. Enable "Join open Invoices"
4. Create an invoice INV01 for customer C01 + Post INV01
5. Go back to Accounting > Customers > Invoices, select INV01
- ! Do not open the invoice. Just select it.
6. Print > Invoices
7. Go to Follow-up Reports
8. Select C01
9. Send by mail
Error: An error message is displayed: "You are trying to send a followup
report to a partner for which you didn't print all the invoices" but it
does not make sense because the invoice has been printed.
For a follow-up report to be sent, the invoices must have the field
`message_main_attachment_id` defined (see
[code](https://github.com/odoo/enterprise/blob/476d862aba396c54c7a47950e02af7aed008a2db/account_followup/models/account_followup_report.py#L311-L313)).
There are two ways for this field to be set:
- When sending the invoice, `_message_set_main_attachment_id` is called,
select one attachment and mark it as main one
https://github.com/odoo/odoo/blob/437b49860b46b5abb8f55ced349fece984968998/addons/mail/models/mail_thread.py#L1918-L1924
- When opening the invoice, if the sreen is large enough, a pdf viewer
is opened next to the invoice. This pdf viewer will call
`register_as_main_attachment`, the latter marks the `ir_attachment` as
main one:
https://github.com/odoo/odoo/blob/e6a41b118a94c5b101d127f6b70fc54958e9346b/addons/mail/models/ir_attachment.py#L17-L20
However, when the user only prints an invoice, nothing will set the
`message_main_attachment_id` field. Thus, this fix will call
`register_as_main_attachment` when a pdf is generated and will mark it
as main attachment.
OPW-2427247
closes odoo/odoo#66282
X-original-commit: 586451e3aaebabda2621c52e8eeb3f3e6ee0d633
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Diffstat (limited to 'addons/account/models/ir_actions_report.py')
| -rw-r--r-- | addons/account/models/ir_actions_report.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/addons/account/models/ir_actions_report.py b/addons/account/models/ir_actions_report.py index 4aa8bb400c2..4c4ba1ead36 100644 --- a/addons/account/models/ir_actions_report.py +++ b/addons/account/models/ir_actions_report.py @@ -29,4 +29,7 @@ class IrActionsReport(models.Model): # don't save the 'account.report_original_vendor_bill' report as it's just a mean to print existing attachments if self.report_name == 'account.report_original_vendor_bill': return None - return super(IrActionsReport, self)._postprocess_pdf_report(record, buffer) + res = super(IrActionsReport, self)._postprocess_pdf_report(record, buffer) + if self.model == 'account.move' and record.is_sale_document(include_receipts=True): + self.retrieve_attachment(record).register_as_main_attachment(force=False) + return res |
