OCA / edi-framework

GNU Affero General Public License v3.0
7 stars 29 forks source link

[17.0][FIX] edi_oca: error in component #107

Closed manuelregidor closed 3 months ago

manuelregidor commented 3 months ago

The component that shows the buttons on the top of the invoices form view is not properly migrated, which is the cause of an error that prevents the access to invoices. This fix sorts out the issue.

T-6447

OCA-git-bot commented 3 months ago

Hi @etobella, @simahawk, some modules you are maintaining are being modified, check this out!

manuelregidor commented 3 months ago

@ValentinVinagre Could you review, please?

etobella commented 3 months ago

Where it was failing? Seeing the JS it shouldn't...

ValentinVinagre commented 3 months ago

@manuelregidor Councillor, could you add some screenshots with the error given by the migration of the "l10n_es_facturae_face" module without this fix? Ty 😃

manuelregidor commented 3 months ago

@etobella

We have identified this issue when migrating the module l10n_es_facturae_face. When trying to access an invoice whose customer has the value "FACe" set in the field l10n_es_facturae_sending_code, a frontend error occurs.

edi_oca_error_1

Complete error:

OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)
    Error: An error occured in the owl lifecycle (see this Error's "cause" property)
        at handleError (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:916:101)
        at App.handleError (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:1545:29)
        at Fiber._render (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:941:19)
        at Fiber.render (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:939:6)
        at ComponentNode.initiateRender (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:1007:47)

Caused by: TypeError: Cannot read properties of undefined (reading 'name')
    at Field.template (eval at compile (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:1503:374), <anonymous>:16:92)
    at Fiber._render (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:940:96)
    at Fiber.render (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:939:6)
    at ComponentNode.initiateRender (http://localhost:17069/web/assets/00a5a52/web.assets_web.min.js:1007:47)

This error is solved by the modifying the file /static/src/js/widget_edi.esm.js. The following lines

EdiConfigurationWidget.template = "edi_oca.EdiConfigurationWidget";

registry.category("fields").add("edi_configuration", EdiConfigurationWidget);

need to be replaced by

EdiConfigurationWidget.template = "edi_oca.EdiConfigurationWidget";

registry.category("fields").add("edi_configuration", {
    component: EdiConfigurationWidget,
});

It is not enough with those changes though, as another error occurs:

edi_oca_error_2

Detailed error:

OwlError: Invalid loop expression: "undefined" is not iterable
    Error: Invalid loop expression: "undefined" is not iterable
        at prepareList (http://localhost:17069/web/assets/83382b6/web.assets_web.min.js:1120:12)
        at EdiConfigurationWidget.template (eval at compile (http://localhost:17069/web/assets/83382b6/web.assets_web.min.js:1503:374), <anonymous>:14:54)
        at Fiber._render (http://localhost:17069/web/assets/83382b6/web.assets_web.min.js:940:96)
        at Fiber.render (http://localhost:17069/web/assets/83382b6/web.assets_web.min.js:939:6)
        at ComponentNode.initiateRender (http://localhost:17069/web/assets/83382b6/web.assets_web.min.js:1007:47)

It is because the component template is not properly defined. That is why the following function has been added to /static/src/js/widget_edi.esm.js file.

    getInfo() {
        return this.props.record.data.edi_config
    }

The way data is retrieved from the template is also modified. These lines

        <t t-foreach="props.value" t-as="rule_id" t-key="rule_index">
            <t t-set="rule" t-value="props.value[rule_id]" />

has been replaced by the following:

        <t t-foreach="this.getInfo()" t-as="rule_id" t-key="rule_index">
            <t t-set="rule" t-value="this.getInfo()[rule_id]" />
ValentinVinagre commented 3 months ago

@peluko00 could u review? https://github.com/OCA/edi-framework/pull/91

manuelregidor commented 3 months ago

@etobella Thanks for your feedback. Changes applied.

OCA-git-bot commented 3 months ago

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

etobella commented 3 months ago

/ocabot merge patch

OCA-git-bot commented 3 months ago

Hey, thanks for contributing! Proceeding to merge this for you. Prepared branch 17.0-ocabot-merge-pr-107-by-etobella-bump-patch, awaiting test results.

OCA-git-bot commented 3 months ago

Congratulations, your PR was merged at e525bbb5b5e495c4b5eb3cd00fdbb95826255474. Thanks a lot for contributing to OCA. ❤️