Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] pass nsmap around (or ns object) #131

Closed
blaggacao opened this issue Sep 27, 2019 · 6 comments
Closed

[IMP] pass nsmap around (or ns object) #131

blaggacao opened this issue Sep 27, 2019 · 6 comments
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.

Comments

@blaggacao
Copy link

Post processing the document requires nsmap for fidelity.
You could generate your own, but at the loss of consistency,

Adjust method signature to pass nsmap around instead of ns(-prefix).

This also helps creating ElementMaker from #128
While #128 is cosmetics, the present issue has more weight.

@blaggacao
Copy link
Author

example

        InvNum = root.findtext("/Invoice/cbc:ID", namespaces=nsmap)

but we only have ns, build according to:

    @api.model
    def _ubl_get_nsmap_namespace(self, doc_name, version='2.1'):
        nsmap = {
            None: 'urn:oasis:names:specification:ubl:schema:xsd:' + doc_name,
            'cac': 'urn:oasis:names:specification:ubl:'
                   'schema:xsd:CommonAggregateComponents-2',
            'cbc': 'urn:oasis:names:specification:ubl:schema:xsd:'
                   'CommonBasicComponents-2',
            }
        ns = {
            'cac': '{urn:oasis:names:specification:ubl:schema:xsd:'
                   'CommonAggregateComponents-2}',
            'cbc': '{urn:oasis:names:specification:ubl:schema:xsd:'
                   'CommonBasicComponents-2}',
            }
        return nsmap, ns

@blaggacao
Copy link
Author

Challenger will be backwards compatibility.

@rvalyi
Copy link
Member

rvalyi commented Sep 28, 2019

guys, just to let you know I'll very soon submit a generic module to work with foreign data models defined by XSD schemas with Odoo. Basically it's based on http://www.davekuhlman.org/generateDS.html
this generator makes XML generator and parser. Then I created a plugin that creates Odoo Abstract mixins that match exactly the XSD structure and can use the Generated XML reader and parser lib to create and read Odoo data models.

Finally I created an Odoo module that makes it easy to inject these mixins into existing Odoo objects like res.partners or account.invoice and specially denormalize or flatten the hierarchies to avoids crazy joins and highly nested forms (while XSD validation typically likes nested tags for a finer grained validation). Alexis always told me UBL is simple enough to be dealt with human written code. May be it is true. Here in Brazil it was not sustainable for the fiscal docs in a open source way. In any case it will work for UBL too, so if you like you may try it soon and see if there is room for improvement in the OCA/edi project too...

@blaggacao
Copy link
Author

blaggacao commented Sep 28, 2019

@rvalyi My experience with generateDS is that it can generate unwieldy huge files. How did you work around it? - but maybe that's not even a real problem, actually. Many thanks for letting us know. As soon as you have a peak preview, please shout. I might not be able to use it for the current need though, maybe when migrating the next time...

EDIT: How would you do the bindings? Through the mentioned odoo module? Are bindings data or code?

@rvalyi
Copy link
Member

rvalyi commented Sep 28, 2019

@blaggacao the XML reader and parser is huge indeed. However when you look at these files in details, you see that except the GeneratedsSuper class, it is may be only twice what you would do by hand if you include the same features. And yes there is that GeneratedsSuper class (that can be shared) but the advantage is your XML parser and reader don't have any extra dependency (unlike say pyXB). As for the Odoo mixins themselves they are as minimalist as they can be. I did a plugin for that, you can see a preview here. It is derivated from the Django plugin but it is not exactly up to date because I'm still doing fine tuning and I am no Mercurial rebase expert https://bitbucket.org/dkuhlman/generateds/pull-requests/51

We will soon push the module to deal with the mixins (not this generator plugin itself) in OCA/l10n_brazil but I guess it may end up interesting lot's of folk dealing with large XSD gramars. I'll let you know when this happen. From a quick look at the UBL XSD's which aren't so small, I tend to think it can be useful here too...

@github-actions
Copy link

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

No branches or pull requests

2 participants