From 098939b20a5ded4c349bb1d09619badc66e51467 Mon Sep 17 00:00:00 2001 From: aliya Date: Mon, 6 Nov 2023 16:00:57 +0100 Subject: [PATCH] [FIX] account_peppol: peppol_move_state One flow wasn't considered in the PR that added a ready state: - A user unchecks BIS3 XML generation and sending via Peppol in the send & print wizard - `peppol_move_state` is set to `ready`, even though it's not possible to send it without the XML file, so it queues forever This commit adds a `skipped` state. If the XML file is not generated, the `peppol_move_state` is changed to `skipped` and the user needs to manually regenerate attachments to send the invoice via Peppol. Also, the BIS3 checkbox shouldn't be deselected automatically when peppol checkbox is deselected. Part-of: odoo/odoo#141258 --- .../models/account_move_send.py | 2 +- addons/account_peppol/i18n/account_peppol.pot | 5 +++++ addons/account_peppol/models/account_move.py | 14 ++++++++++++++ addons/account_peppol/wizard/account_move_send.py | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/account_edi_ubl_cii/models/account_move_send.py b/addons/account_edi_ubl_cii/models/account_move_send.py index 6f6088b6e60..e31c5774272 100644 --- a/addons/account_edi_ubl_cii/models/account_move_send.py +++ b/addons/account_edi_ubl_cii/models/account_move_send.py @@ -53,7 +53,7 @@ class AccountMoveSend(models.TransientModel): @api.depends('enable_ubl_cii_xml') def _compute_checkbox_ubl_cii_xml(self): for wizard in self: - wizard.checkbox_ubl_cii_xml = wizard.enable_ubl_cii_xml and wizard.company_id.invoice_is_ubl_cii + wizard.checkbox_ubl_cii_xml = wizard.enable_ubl_cii_xml and (wizard.checkbox_ubl_cii_xml or wizard.company_id.invoice_is_ubl_cii) # ------------------------------------------------------------------------- # ATTACHMENTS diff --git a/addons/account_peppol/i18n/account_peppol.pot b/addons/account_peppol/i18n/account_peppol.pot index 8769f5e07a1..3b89b7ffba1 100644 --- a/addons/account_peppol/i18n/account_peppol.pot +++ b/addons/account_peppol/i18n/account_peppol.pot @@ -597,6 +597,11 @@ msgstr "" msgid "Send via PEPPOL" msgstr "" +#. module: account_peppol +#: model:ir.model.fields.selection,name:account_peppol.selection__account_move__peppol_move_state__skipped +msgid "Skipped" +msgstr "" + #. module: account_peppol #: model_terms:ir.ui.view,arch_db:account_peppol.res_config_settings_view_form msgid "" diff --git a/addons/account_peppol/models/account_move.py b/addons/account_peppol/models/account_move.py index 9486942354e..4eb1b7042cb 100644 --- a/addons/account_peppol/models/account_move.py +++ b/addons/account_peppol/models/account_move.py @@ -13,6 +13,7 @@ class AccountMove(models.Model): selection=[ ('ready', 'Ready to send'), ('to_send', 'Queued'), + ('skipped', 'Skipped'), ('processing', 'Pending Reception'), ('canceled', 'Canceled'), ('done', 'Done'), @@ -24,6 +25,19 @@ class AccountMove(models.Model): ) peppol_is_demo_uuid = fields.Boolean(compute="_compute_peppol_is_demo_uuid") + @api.model + def fields_get(self, allfields=None, attributes=None): + res = super().fields_get(allfields, attributes) + + # the orm_cache does not contain the new selections added in stable: clear the cache once + peppol_move_state_field = self._fields['peppol_move_state'] + if ('skipped', "Skipped") not in peppol_move_state_field.get_description(self.env)['selection']: + self.env['ir.model.fields'].invalidate_model(['selection_ids']) + self.env['ir.model.fields.selection']._update_selection( + 'account.move', 'peppol_move_state', peppol_move_state_field.selection) + self.env.registry.clear_cache() + return res + def action_cancel_peppol_documents(self): # if the peppol_move_state is processing/done # then it means it has been already sent to peppol proxy and we can't cancel diff --git a/addons/account_peppol/wizard/account_move_send.py b/addons/account_peppol/wizard/account_move_send.py index 22ca2c77d8a..0c602369797 100644 --- a/addons/account_peppol/wizard/account_move_send.py +++ b/addons/account_peppol/wizard/account_move_send.py @@ -130,6 +130,7 @@ class AccountMoveSend(models.TransientModel): xml_file = invoice.ubl_cii_xml_id.raw filename = invoice.ubl_cii_xml_id.name else: + invoice.peppol_move_state = 'skipped' continue if not invoice.partner_id.peppol_eas or not invoice.partner_id.peppol_endpoint: