diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index a4c826dddb370..a966db153a7ab 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -603,6 +603,16 @@ def _sequence_year_range_monthly_regex(self): tracking=True, help="It indicates that the invoice/payment has been sent or the PDF has been generated.", ) + + move_sent_state = fields.Selection( + selection=[('not_sent', "Not Sent"), ('sent', "Sent")], + default='not_sent', + tracking=True, + copy=False, + readonly=True, + help="It indicates that the invoice/payment has been sent or the PDF has been generated.", + ) + is_being_sent = fields.Boolean( help="Is the move being sent asynchronously", compute='_compute_is_being_sent' diff --git a/addons/account/models/account_move_send.py b/addons/account/models/account_move_send.py index 4cceccc5c6ec8..96bb82e54aa51 100644 --- a/addons/account/models/account_move_send.py +++ b/addons/account/models/account_move_send.py @@ -412,7 +412,7 @@ def _link_invoice_documents(self, invoices_data): if attachment := res_id_to_attachment.get(invoice.id): invoice.message_main_attachment_id = attachment invoice.invalidate_recordset(fnames=['invoice_pdf_report_id', 'invoice_pdf_report_file']) - invoice.is_move_sent = True + invoice.move_sent_state = 'sent' @api.model def _hook_if_errors(self, moves_data, allow_raising=True): diff --git a/addons/account/tests/test_account_move_send.py b/addons/account/tests/test_account_move_send.py index 033ac5c0ce6b9..fa720167c6aad 100644 --- a/addons/account/tests/test_account_move_send.py +++ b/addons/account/tests/test_account_move_send.py @@ -157,7 +157,7 @@ def test_move_composer_multi(self): move_template = self.move_template.with_env(self.env) for test_move in test_moves: - self.assertFalse(test_move.is_move_sent) + self.assertEqual(test_move.move_sent_state, 'not_sent') with self.mock_mail_gateway(mail_unlink_sent=False): self.env['account.move.send']._generate_and_send_invoices( @@ -214,7 +214,7 @@ def test_move_composer_multi(self): # invoice update for test_move in test_moves: - self.assertTrue(test_move.is_move_sent) + self.assertEqual(test_move.move_sent_state, 'sent') @users('user_account') @warmup @@ -256,10 +256,10 @@ def test_move_composer_single(self): 'Should take invoice_user_id email') self.assertEqual(print_msg.notified_partner_ids, test_customer + self.user_accountman.partner_id) self.assertEqual(print_msg.subject, f'{self.env.user.company_id.name} Invoice (Ref {test_move.name})') - # tracking: is_move_sent + # tracking: move_sent_state self.assertEqual(track_msg.author_id, self.env.user.partner_id) self.assertEqual(track_msg.email_from, self.env.user.email_formatted) - self.assertTrue('is_move_sent' in track_msg.tracking_value_ids.field_id.mapped('name')) + self.assertTrue('move_sent_state' in track_msg.tracking_value_ids.field_id.mapped('name')) # sent email self.assertMailMail( test_customer, @@ -301,7 +301,7 @@ def test_move_composer_single(self): self.assertEqual(composer.mail_template_id, move_template) # invoice update - self.assertTrue(test_move.is_move_sent) + self.assertEqual(test_move.move_sent_state, 'sent') @users('user_account') @warmup @@ -343,10 +343,10 @@ def test_move_composer_single_lang(self): 'Should take invoice_user_id email') self.assertEqual(print_msg.notified_partner_ids, test_customer + self.user_accountman.partner_id) self.assertEqual(print_msg.subject, f'SpanishSubject for {test_move.name}') - # tracking: is_move_sent + # tracking: move_sent_state self.assertEqual(track_msg.author_id, self.env.user.partner_id) self.assertEqual(track_msg.email_from, self.env.user.email_formatted) - self.assertTrue('is_move_sent' in track_msg.tracking_value_ids.field_id.mapped('name')) + self.assertTrue('move_sent_state' in track_msg.tracking_value_ids.field_id.mapped('name')) # sent email self.assertMailMail( test_customer, @@ -390,7 +390,7 @@ def test_move_composer_single_lang(self): self.assertEqual(composer.mail_template_id, move_template) # invoice update - self.assertTrue(test_move.is_move_sent) + self.assertEqual(test_move.move_sent_state, 'sent') @users('user_account') @warmup @@ -1061,22 +1061,22 @@ def _hook_invoice_document_before_pdf_report_render(self, invoice, invoice_data) self.assertEqual(payload_2['type'], 'warning') self.assertEqual(sorted(payload_2['action_button']['res_ids']), invoices_error.ids) - def test_is_move_sent_state(self): + def test_move_sent_state(self): # Post a move, nothing sent yet invoice = self.init_invoice("out_invoice", amounts=[1000], post=True) - self.assertFalse(invoice.is_move_sent) + self.assertEqual(invoice.move_sent_state, 'not_sent') # Send via send & print wizard = self.create_send_and_print(invoice) wizard.action_send_and_print() - self.assertTrue(invoice.is_move_sent) + self.assertEqual(invoice.move_sent_state, 'sent') # Revert move to draft invoice.button_draft() - self.assertTrue(invoice.is_move_sent) + self.assertEqual(invoice.move_sent_state, 'sent') # Unlink PDF pdf_report = invoice.invoice_pdf_report_id self.assertTrue(pdf_report) invoice.invoice_pdf_report_id.unlink() - self.assertTrue(invoice.is_move_sent) + self.assertEqual(invoice.move_sent_state, 'sent') def test_no_sending_method_selected(self): invoice = self.init_invoice("out_invoice", amounts=[1000], post=True) @@ -1084,7 +1084,7 @@ def test_no_sending_method_selected(self): wizard = self.create_send_and_print(invoice, sending_methods=[]) self.assertFalse(wizard.sending_methods) wizard.action_send_and_print() - self.assertTrue(invoice.is_move_sent) + self.assertEqual(invoice.move_sent_state, 'sent') self.assertTrue(invoice.invoice_pdf_report_id) def test_get_sending_settings(self): diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index 5ed5e8aa6eaeb..8cf9048873bf2 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -548,6 +548,12 @@ invisible="payment_state == 'invoicing_legacy' or move_type == 'entry'" optional="show" /> + @@ -922,7 +928,7 @@ - + @@ -1024,7 +1030,7 @@ context="{'default_partner_id': bank_partner_id, 'display_account_trust': True}" domain="[('partner_id', '=', bank_partner_id)]" invisible="move_type not in ('in_invoice', 'in_refund', 'in_receipt')" - readonly="is_move_sent and state != 'draft'"/> + readonly="move_sent_state == 'sent' and state != 'draft'"/>
@@ -1403,7 +1409,7 @@ + readonly="move_sent_state == 'sent' and state != 'draft'"/> - + + diff --git a/addons/l10n_tr_nilvera_einvoice/models/account_move.py b/addons/l10n_tr_nilvera_einvoice/models/account_move.py index 3189bf25e730f..84c171fdcb266 100644 --- a/addons/l10n_tr_nilvera_einvoice/models/account_move.py +++ b/addons/l10n_tr_nilvera_einvoice/models/account_move.py @@ -83,7 +83,7 @@ def _l10n_tr_nilvera_submit_document(self, xml_file, endpoint, post_series=True) ) if response.status_code == 200: - self.is_move_sent = True + self.move_sent_state = 'sent' self.l10n_tr_nilvera_send_status = 'sent' elif response.status_code in {401, 403}: raise UserError(_("Oops, seems like you're unauthorised to do this. Try another API key with more rights or contact Nilvera.")) diff --git a/addons/l10n_tr_nilvera_einvoice/models/account_move_send.py b/addons/l10n_tr_nilvera_einvoice/models/account_move_send.py index dddc606c4a079..1d30ea9dd1685 100644 --- a/addons/l10n_tr_nilvera_einvoice/models/account_move_send.py +++ b/addons/l10n_tr_nilvera_einvoice/models/account_move_send.py @@ -44,7 +44,7 @@ def _link_invoice_documents(self, invoices_data): # The move needs to be put as sent only if sent by Nilvera for invoice, invoice_data in invoices_data.items(): if invoice.company_id.country_code == 'TR': - invoice.is_move_sent = invoice.l10n_tr_nilvera_send_status == 'sent' + invoice.move_sent_state = 'sent' if invoice.l10n_tr_nilvera_send_status == 'sent' else 'not_sent' @api.model diff --git a/addons/sale/models/payment_transaction.py b/addons/sale/models/payment_transaction.py index 33c944e138a19..2958293332177 100644 --- a/addons/sale/models/payment_transaction.py +++ b/addons/sale/models/payment_transaction.py @@ -148,9 +148,9 @@ def _send_invoice(self): company_id=tx.company_id.id, ) invoice_to_send = tx.invoice_ids.filtered( - lambda i: not i.is_move_sent and i.state == 'posted' and i._is_ready_to_be_sent() + lambda i: i.move_sent_state == 'not_sent' and i.state == 'posted' and i._is_ready_to_be_sent() ) - invoice_to_send.is_move_sent = True # Mark invoice as sent + invoice_to_send.move_sent_state = 'sent' # Mark invoice as sent self.env['account.move.send']._generate_and_send_invoices( invoice_to_send, allow_raising=False, @@ -171,7 +171,7 @@ def _cron_send_invoice(self): ('state', '=', 'done'), ('is_post_processed', '=', True), ('invoice_ids', 'in', self.env['account.move']._search([ - ('is_move_sent', '=', False), + ('move_sent_state', '=', 'not_sent'), ('state', '=', 'posted'), ])), ('sale_order_ids.state', '=', 'sale'), diff --git a/addons/sale/tests/test_payment_flow.py b/addons/sale/tests/test_payment_flow.py index f25e2be82907c..914633472b8ee 100644 --- a/addons/sale/tests/test_payment_flow.py +++ b/addons/sale/tests/test_payment_flow.py @@ -256,7 +256,7 @@ def test_auto_done_and_auto_invoice(self): self.assertTrue(self.sale_order.locked) self.assertTrue(tx.invoice_ids) self.assertTrue(self.sale_order.invoice_ids) - self.assertTrue(tx.invoice_ids.is_move_sent) + self.assertEqual(tx.invoice_ids.move_sent_state, 'sent') def test_so_partial_payment_no_invoice(self): # Set automatic invoice