Giter Site home page Giter Site logo

Comments (7)

blaggacao avatar blaggacao commented on July 26, 2024

Same for cbc:RegistrationName (which is not necesarily identical to res.partner.name) - res.partner.name can be used for well known commercial insignia (eg. brand).

from edi.

blaggacao avatar blaggacao commented on July 26, 2024

It happens so that both have the same signature:

Therefore the existing localization machinery can be reused:

    @api.model
    def _ubl_get_party_identification(self, commercial_partner):
        '''This method is designed to be inherited in localisation modules
        Should return a dict with key=SchemeName, value=Identifier'''
        return {}

    @api.model
    def _ubl_add_party_identification(
            self, commercial_partner, parent_node, ns, version='2.1'):
        id_dict = self._ubl_get_party_identification(commercial_partner)
        if id_dict:
            party_identification = etree.SubElement(
                parent_node, ns['cac'] + 'PartyIdentification')
            for scheme_name, party_id_text in id_dict.items():
                party_identification_id = etree.SubElement(
                    party_identification, ns['cbc'] + 'ID',
                    schemeName=scheme_name)
                party_identification_id.text = party_id_text
        return

EDIT: This localization machinery must support all available attributes.

from edi.

blaggacao avatar blaggacao commented on July 26, 2024

Proposal:

    @api.model
    def _ubl_get_party_identification(self, commercial_partner):
        '''This method is designed to be inherited in localisation modules
        Should return a list of dict reflecting the json xml notation of
            - either cbe:IDType
            - or: cbc:CompanyIDType
        which both have identical signatures.
        Example:
        {
            "IdentifierContent":"DK12345",
            "IdentificationSchemeIdentifier":"DKVAT",
            "IdentificationSchemeNameText":"DKVAT",
            "IdentificationSchemeAgencyIdentifier":"ZZZ",
            "IdentificationSchemeAgencyNameText":"ZZZ",
            "IdentificationSchemeVersionIdentifier":"ZZZ",
            "IdentificationSchemeDataUniformResourceIdentifier":"ZZZ",
            "IdentificationSchemeUniformResourceIdentifier":"ZZZ",
        }
        Full spec: http://docs.oasis-open.org/ubl/UBL-2.1-JSON/v1.0/cnd02/
                   /json-schema/common/CCTS_CCT_SchemaModule-2.1.json
        '''
        return []

    @api.model
    def _ubl_add_id_type(self, id_dict, node_name, parent_node, ns, version='2.1'):
        if "IdentifierContent" not in id_dict:
            raise UserError(_(
                "No 'IdentiferContent' provided for '%s'")
                % node_name)
        json_to_xml_attrs = {
            "IdentificationSchemeIdentifier": "schemeID",
            "IdentificationSchemeNameText": "schemeName",
            "IdentificationSchemeAgencyIdentifier": "schemeAgencyID",
            "IdentificationSchemeAgencyNameText": "schemeAgencyName",
            "IdentificationSchemeVersionIdentifier": "schemeVersionID",
            "IdentificationSchemeDataUniformResourceIdentifier": "schemeDataURI",
            "IdentificationSchemeUniformResourceIdentifier": "schemeURI",
        }
        iid = etree.SubElement(
            parent_node,
            ns['cbc'] + node_name,
            **dict(
                (json_to_xml_attrs[key], value)
                for (key, value) in id_dict.items()
                if key in json_to_xml_attrs
            )
        )
        iid.text = id_dict['IdentifierContent']

    @api.model
    def _ubl_add_party_identification(
            self, commercial_partner, parent_node, ns, version='2.1'):
        id_dicts = self._ubl_get_party_identification(commercial_partner)
        if id_dicts:
            party_identification = etree.SubElement(
                parent_node, ns['cac'] + 'PartyIdentification')
            for id_dict in id_dicts:
                self._ubl_add_id_type(
                    id_dict, 'ID', party_identification, ns, version=version)
        return

Mimicks the official JSON Alternative Representation V1.0 as python dict.
A little verbose, but well documented, standard conformant and sufficiently expressive.

from edi.

blaggacao avatar blaggacao commented on July 26, 2024

/cc @Deiber

from edi.

astirpe avatar astirpe commented on July 26, 2024

@blaggacao I get the idea behind your proposal #126 (comment) and it looks good to me.

from edi.

blaggacao avatar blaggacao commented on July 26, 2024

I went a little further and made "dict parsers" for UBL IdentifierType TextType and CodeType. THis way we can construe more complex TaxScheme instances. Once I've get a patch working for my case, I'll share it.

from edi.

github-actions avatar github-actions commented on July 26, 2024

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.

from edi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.