From 4cc2cb93da16227c02e8fe85006e0fb1b3258ca4 Mon Sep 17 00:00:00 2001 From: det Date: Fri, 24 Mar 2023 13:30:05 +0000 Subject: [PATCH] [IMP] account: mark invoice as sent once pdf generated Before this commit, the invoices were marked as sent only when sending them via email or post. After, it is mark as sent once the PDF is being generated via the send&print wizard, as it becomes computed based on the presence of the PDF. Rational, we want to consider a generated invoice via the send&print wizard as being sent as it can be printed/downloaded. This also makes the invoice available in the portal. closes odoo/odoo#117085 X-original-commit: 9e656aabe4f6840ee5c200a21832dad958ea6892 Signed-off-by: Laurent Smet Signed-off-by: Detry Thomas (det) --- addons/account/models/account_move.py | 10 +++++++++- addons/account/wizard/account_move_send.py | 2 +- addons/snailmail_account/wizard/account_move_send.py | 2 -- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index b344731561f..86081a1b3a4 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -502,8 +502,11 @@ class AccountMove(models.Model): default=False, copy=False, tracking=True, - help="It indicates that the invoice/payment has been sent.", + store=True, + compute="_compute_is_move_sent", + help="It indicates that the invoice/payment has been sent or the PDF has been generated.", ) + invoice_user_id = fields.Many2one( string='Salesperson', comodel_name='res.users', @@ -610,6 +613,11 @@ class AccountMove(models.Model): # COMPUTE METHODS # ------------------------------------------------------------------------- + @api.depends('invoice_pdf_report_id') + def _compute_is_move_sent(self): + for move in self: + move.is_move_sent = bool(move.invoice_pdf_report_id) + def _compute_payment_reference(self): for move in self.filtered(lambda m: ( m.state == 'posted' diff --git a/addons/account/wizard/account_move_send.py b/addons/account/wizard/account_move_send.py index 9062510d248..dbd47aaef6a 100644 --- a/addons/account/wizard/account_move_send.py +++ b/addons/account/wizard/account_move_send.py @@ -343,7 +343,6 @@ class AccountMoveSend(models.Model): 'reply_to_force_new': False, }, ) - move.is_move_sent = True def _send_mails(self, moves): subtype = self.env.ref('mail.mt_comment') @@ -393,6 +392,7 @@ class AccountMoveSend(models.Model): # note: Binary is used for security reason self.env['ir.attachment'].create(prepared_data['pdf_attachment_values']) invoice.invalidate_model(fnames=['invoice_pdf_report_id', 'invoice_pdf_report_file']) + self.env.add_to_compute(invoice._fields['is_move_sent'], invoice) def _postprocess_document(self, invoice, prepared_data): """ Postprocess prepared_data before it gets linked to the record diff --git a/addons/snailmail_account/wizard/account_move_send.py b/addons/snailmail_account/wizard/account_move_send.py index 5e166f92102..0b78ff7afb6 100644 --- a/addons/snailmail_account/wizard/account_move_send.py +++ b/addons/snailmail_account/wizard/account_move_send.py @@ -68,6 +68,4 @@ class AccountMoveSend(models.Model): ])\ ._snailmail_print(immediate=False) - moves.is_move_sent = True - return moves