From df28dcab4e23b55149be77e1e019b2363dda9f80 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Fri, 20 Dec 2024 13:34:24 +0000 Subject: [PATCH] [MIG] l10n_pt_account_invoicexpress: migration to 17.0 --- l10n_pt_account_invoicexpress/README.rst | 38 +++++++++++-------- .../models/account_invoicexpress.py | 9 ++++- .../models/account_move.py | 18 +++++---- .../readme/CONFIGURE.md | 6 ++- .../readme/DESCRIPTION.md | 15 +------- l10n_pt_account_invoicexpress/readme/USAGE.md | 13 +++++++ .../static/description/index.html | 34 +++++++++-------- .../tests/test_invoicexpress.py | 2 +- .../views/res_company_view.xml | 2 +- .../views/res_config_settings.xml | 12 ++---- 10 files changed, 85 insertions(+), 64 deletions(-) diff --git a/l10n_pt_account_invoicexpress/README.rst b/l10n_pt_account_invoicexpress/README.rst index 654079e5..4c9d1cc4 100644 --- a/l10n_pt_account_invoicexpress/README.rst +++ b/l10n_pt_account_invoicexpress/README.rst @@ -31,18 +31,6 @@ Portugal InvoiceXpress Integration Generate Portuguese tax authority legal Invoices ("Faturas") using InvoiceXpress. -**UPDATE November/2021:** - -Invoices: - -- Added support to the different documents types: Invoice, Invoice - Receipt, Simplified Invoice. The default document type is set on the - Journal, and can be changed on the Invoice form. -- Use the invoice commercial partner for the name and address, instead - of the invoice contact. -- Added support for the Terms and Conditions/Observations field -- Added to Credit Notes the link to the source Invoice - InvoiceXpress is a paid service. Visit https://invoicexpress.com for more details. @@ -58,8 +46,8 @@ generated document should be used. Having other print layouts for the invoice is not allowed by the Portuguese Tax Authority. Legal transport documents ("Guias de Transporte" e "Guias de Remessa) -are also supported through the extension module -"l10n_pt_stock_invoicexpress". +are also supported through an extension module. For this please ensure +that "l10n_pt_stock_invoicexpress" is installed. **Table of contents** @@ -72,13 +60,18 @@ Configuration To configure: - Navigate to Settings/General Settings. -- In the "General Settings" configuration section, locate the - "InvoiceXpress" subsection: There you can set: + +- In the "Invoicing" configuration section, locate the "InvoiceXpress" + subsection: There you can set: - InvoiceXpress Account Name - InvoiceXpress API Key - InvoiceXpress Invoice Email Template +- In "Invoicing/Accounting" configuration section, locate the Sales + Journals, and set the "InvoiceXpress Doc Type". This is required + before invoices before any invoice can be created. + The email template is used to prepare the details for the email the InvoiceXpress service sends with the invoice: @@ -117,6 +110,19 @@ send an email with a copy of the legal document. The Invoice form shows an "InvoiceXpress" tab containing details for the corresponding InvoiceXpress document. +Invoices: + +- Added support to the different documents types: Invoice, Invoice + Receipt, Simplified Invoice. The default document type is set on the + Journal, and can be changed on the Invoice form. +- Use the invoice commercial partner for the name and address, instead + of the invoice contact. +- Added support for the Terms and Conditions/Observations field +- Added to Credit Notes the link to the source Invoice + +The monthly SAF-T file should be downloaded from the InvoiceXpress +website. + Bug Tracker =========== diff --git a/l10n_pt_account_invoicexpress/models/account_invoicexpress.py b/l10n_pt_account_invoicexpress/models/account_invoicexpress.py index dc3ade8d..47157216 100644 --- a/l10n_pt_account_invoicexpress/models/account_invoicexpress.py +++ b/l10n_pt_account_invoicexpress/models/account_invoicexpress.py @@ -56,12 +56,19 @@ def _check_http_status(self, response): """ # TODO: implement request rate limit if response.status_code not in [200, 201]: + if response.json(): + msg = "\n".join( + "- " + (x.get("error") or repr(x)) + for x in response.json().get("errors", []) + ) + else: + msg = repr(response.json()) raise exceptions.ValidationError( _("Error running API request (%(status_code)s %(reason)s):\n%(json)s") % { "status_code": response.status_code, "reason": response.reason, - "json": response.json(), + "json": msg, } ) diff --git a/l10n_pt_account_invoicexpress/models/account_move.py b/l10n_pt_account_invoicexpress/models/account_move.py index 5117ef35..bb2b8b5f 100644 --- a/l10n_pt_account_invoicexpress/models/account_move.py +++ b/l10n_pt_account_invoicexpress/models/account_move.py @@ -3,6 +3,8 @@ import uuid +from markupsafe import Markup + from odoo import _, api, exceptions, fields, models @@ -202,7 +204,7 @@ def _update_invoicexpress_status(self): "" ).format(inv_xpress_id=self.invoicexpress_id, inv_xpress_link=inv_xpress_link) - self.message_post(body=msg) + self.message_post(body=Markup(msg)) def action_create_invoicexpress_invoice(self): InvoiceXpress = self.env["account.invoicexpress"] @@ -240,7 +242,7 @@ def action_create_invoicexpress_invoice(self): ) ) prefix = self._get_invoicexpress_prefix(doctype) - invx_number = f"{prefix}, {seqnum}" if prefix else seqnum + invx_number = f"{prefix} {seqnum}" if prefix else seqnum if invoice.payment_reference == invoice.name: invoice.payment_reference = invx_number invoice.name = invx_number @@ -249,9 +251,6 @@ def action_create_invoicexpress_invoice(self): def _prepare_invoicexpress_email_vals(self, ignore_no_config=False): self.ensure_one() template_id = self.company_id.invoicexpress_template_id - values = template_id.generate_email( - self.id, ["subject", "body_html", "email_to", "email_cc"] - ) if not template_id and not ignore_no_config: raise exceptions.UserError( _( @@ -259,6 +258,9 @@ def _prepare_invoicexpress_email_vals(self, ignore_no_config=False): " at Settings > General Setting, InvoiceXpress section" ) ) + values = template_id._generate_template( + [self.id], ["subject", "body_html", "email_to", "email_cc"] + )[self.id] if not values.get("email_to") and not ignore_no_config: raise exceptions.UserError(_("No address to send invoice email to.")) email_data = None @@ -288,12 +290,12 @@ def action_send_invoicexpress_email(self, ignore_no_config=False): InvoiceXpress.call(invoice.company_id, endpoint, "PUT", payload=payload) msg = _( "Email sent by InvoiceXpress:" + "{email}
  • Cc:{cc}
  • " ).format( email=payload["message"]["client"]["email"], cc=payload["message"]["cc"] or _("None"), ) - invoice.message_post(body=msg) + invoice.message_post(body=Markup(msg)) def _post(self, soft=True): res = super()._post(soft=soft) @@ -337,7 +339,7 @@ def _mark_invoice_paid(self): ) ) msg = _("InvoiceXpress record has been modified to Paid.") - self.message_post(body=msg) + self.message_post(body=Markup(msg)) class AccountMoveLine(models.Model): diff --git a/l10n_pt_account_invoicexpress/readme/CONFIGURE.md b/l10n_pt_account_invoicexpress/readme/CONFIGURE.md index cf2511a3..fc9882d5 100644 --- a/l10n_pt_account_invoicexpress/readme/CONFIGURE.md +++ b/l10n_pt_account_invoicexpress/readme/CONFIGURE.md @@ -1,12 +1,16 @@ To configure: - Navigate to Settings/General Settings. -- In the "General Settings" configuration section, locate the +- In the "Invoicing" configuration section, locate the "InvoiceXpress" subsection: There you can set: - InvoiceXpress Account Name - InvoiceXpress API Key - InvoiceXpress Invoice Email Template +- In "Invoicing/Accounting" configuration section, locate the + Sales Journals, and set the "InvoiceXpress Doc Type". + This is required before invoices before any invoice can be created. + The email template is used to prepare the details for the email the InvoiceXpress service sends with the invoice: diff --git a/l10n_pt_account_invoicexpress/readme/DESCRIPTION.md b/l10n_pt_account_invoicexpress/readme/DESCRIPTION.md index 108f7d0a..1b8d5348 100644 --- a/l10n_pt_account_invoicexpress/readme/DESCRIPTION.md +++ b/l10n_pt_account_invoicexpress/readme/DESCRIPTION.md @@ -1,17 +1,6 @@ Generate Portuguese tax authority legal Invoices ("Faturas") using InvoiceXpress. -**UPDATE November/2021:** - -Invoices: - -- Added support to the different documents types: Invoice, Invoice - Receipt, Simplified Invoice. The default document type is set on the - Journal, and can be changed on the Invoice form. -- Use the invoice commercial partner for the name and address, instead - of the invoice contact. -- Added support for the Terms and Conditions/Observations field -- Added to Credit Notes the link to the source Invoice InvoiceXpress is a paid service. Visit for more details. @@ -28,5 +17,5 @@ generated document should be used. Having other print layouts for the invoice is not allowed by the Portuguese Tax Authority. Legal transport documents ("Guias de Transporte" e "Guias de Remessa) -are also supported through the extension module -"l10n_pt_stock_invoicexpress". +are also supported through an extension module. For this please ensure that +"l10n_pt_stock_invoicexpress" is installed. diff --git a/l10n_pt_account_invoicexpress/readme/USAGE.md b/l10n_pt_account_invoicexpress/readme/USAGE.md index 82a27fb4..c0ad0dba 100644 --- a/l10n_pt_account_invoicexpress/readme/USAGE.md +++ b/l10n_pt_account_invoicexpress/readme/USAGE.md @@ -6,3 +6,16 @@ send an email with a copy of the legal document. The Invoice form shows an "InvoiceXpress" tab containing details for the corresponding InvoiceXpress document. + +Invoices: + +- Added support to the different documents types: Invoice, Invoice + Receipt, Simplified Invoice. The default document type is set on the + Journal, and can be changed on the Invoice form. +- Use the invoice commercial partner for the name and address, instead + of the invoice contact. +- Added support for the Terms and Conditions/Observations field +- Added to Credit Notes the link to the source Invoice + + +The monthly SAF-T file should be downloaded from the InvoiceXpress website. diff --git a/l10n_pt_account_invoicexpress/static/description/index.html b/l10n_pt_account_invoicexpress/static/description/index.html index c50c7dbe..5fec30de 100644 --- a/l10n_pt_account_invoicexpress/static/description/index.html +++ b/l10n_pt_account_invoicexpress/static/description/index.html @@ -372,17 +372,6 @@

    Portugal InvoiceXpress Integration

    Production/Stable License: AGPL-3 OCA/l10n-portugal Translate me on Weblate Try me on Runboat

    Generate Portuguese tax authority legal Invoices (“Faturas”) using InvoiceXpress.

    -

    UPDATE November/2021:

    -

    Invoices:

    -

    InvoiceXpress is a paid service. Visit https://invoicexpress.com for more details.

    Once the InvoiceXpress connection is configured, the invoice CONFIRM @@ -394,8 +383,8 @@

    Portugal InvoiceXpress Integration

    generated document should be used. Having other print layouts for the invoice is not allowed by the Portuguese Tax Authority.

    Legal transport documents (“Guias de Transporte” e “Guias de Remessa) -are also supported through the extension module -“l10n_pt_stock_invoicexpress”.

    +are also supported through an extension module. For this please ensure +that “l10n_pt_stock_invoicexpress” is installed.

    Table of contents

      @@ -415,13 +404,16 @@

      Configuration

      To configure:

      • Navigate to Settings/General Settings.
      • -
      • In the “General Settings” configuration section, locate the -“InvoiceXpress” subsection: There you can set:
          +
        • In the “Invoicing” configuration section, locate the “InvoiceXpress” +subsection: There you can set:
          • InvoiceXpress Account Name
          • InvoiceXpress API Key
          • InvoiceXpress Invoice Email Template
        • +
        • In “Invoicing/Accounting” configuration section, locate the Sales +Journals, and set the “InvoiceXpress Doc Type”. This is required +before invoices before any invoice can be created.

        The email template is used to prepare the details for the email the InvoiceXpress service sends with the invoice:

        @@ -454,6 +446,18 @@

        Usage

        send an email with a copy of the legal document.

        The Invoice form shows an “InvoiceXpress” tab containing details for the corresponding InvoiceXpress document.

        +

        Invoices:

        +
          +
        • Added support to the different documents types: Invoice, Invoice +Receipt, Simplified Invoice. The default document type is set on the +Journal, and can be changed on the Invoice form.
        • +
        • Use the invoice commercial partner for the name and address, instead +of the invoice contact.
        • +
        • Added support for the Terms and Conditions/Observations field
        • +
        • Added to Credit Notes the link to the source Invoice
        • +
        +

        The monthly SAF-T file should be downloaded from the InvoiceXpress +website.

    Bug Tracker

    diff --git a/l10n_pt_account_invoicexpress/tests/test_invoicexpress.py b/l10n_pt_account_invoicexpress/tests/test_invoicexpress.py index df8ab0b1..e8d859d8 100644 --- a/l10n_pt_account_invoicexpress/tests/test_invoicexpress.py +++ b/l10n_pt_account_invoicexpress/tests/test_invoicexpress.py @@ -125,4 +125,4 @@ def test_101_create_invoicexpress_invoice(self, mock_request): invoice.action_post() self.assertEqual(invoice.invoicexpress_doc_type, "invoice_receipt") self.assertEqual(invoice.invoicexpress_id, "12345678") - self.assertEqual(invoice.name, "FR, MYSEQ/123") + self.assertEqual(invoice.name, "FR MYSEQ/123") diff --git a/l10n_pt_account_invoicexpress/views/res_company_view.xml b/l10n_pt_account_invoicexpress/views/res_company_view.xml index fe13fb5c..e4c3f28e 100644 --- a/l10n_pt_account_invoicexpress/views/res_company_view.xml +++ b/l10n_pt_account_invoicexpress/views/res_company_view.xml @@ -11,7 +11,7 @@ - + diff --git a/l10n_pt_account_invoicexpress/views/res_config_settings.xml b/l10n_pt_account_invoicexpress/views/res_config_settings.xml index 7f20a190..cb2c37d4 100644 --- a/l10n_pt_account_invoicexpress/views/res_config_settings.xml +++ b/l10n_pt_account_invoicexpress/views/res_config_settings.xml @@ -3,14 +3,10 @@ res.config.settings.view.form.invoicexpress res.config.settings - + - - + + - +