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

Item and buyer ledger implementation #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

kmate129
Copy link

Introduces the implementation of Buyer Ledger and Item Ledger classes and integrates them into the existing template. In accordance with the xsd, I dynamically defined both ledgers and their fields as optional, deviating from the previous template description.

Comment on lines 64 to 79
{% set ledger_fields = {
"konyvelesDatum": buyer.buyer_ledger.accounting_date,
"vevoAzonosito": buyer.buyer_ledger.buyer_identifier,
"vevoFokonyviSzam": buyer.buyer_ledger.buyer_ledger_number,
"folyamatosTelj": buyer.buyer_ledger.continuous_performance | lower,
"elszDatumTol": buyer.buyer_ledger.settlement_date_from,
"elszDatumIg": buyer.buyer_ledger.settlement_date_to
} %}

{% if ledger_fields.values() | select("string") | list %}
<vevoFokonyv>
{% for key, value in ledger_fields.items() if value %}
<{{ key }}>{{ value }}</{{ key }}>
{% endfor %}
</vevoFokonyv>
{% endif %}
Copy link
Owner

@theriverman theriverman Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes this inline dict declaration necessary compared to adding the actual XML template between an IF-block? For example, it could look something like this:

        {% if buyer.buyer_ledger %}
        <vevoFokonyv>
            <konyvelesDatum>{{ buyer.buyer_ledger.accounting_date }}</konyvelesDatum>
            <vevoAzonosito>{{ buyer.buyer_ledger.buyer_identifier }}</vevoAzonosito>
            <vevoFokonyviSzam>{{ buyer.buyer_ledger.buyer_ledger_number }}</vevoFokonyviSzam>
            <folyamatosTelj>{{ buyer.buyer_ledger.continuous_performance }}</folyamatosTelj>
            <elszDatumTol>{{ buyer.buyer_ledger.settlement_date_from }}</elszDatumTol>
            <elszDatumIg>{{ buyer.buyer_ledger.settlement_date_to }}</elszDatumIg>
        </vevoFokonyv>
        {% endif %}

If buyer.buyer_ledger is true, we're safe to add the whole block to the request and this block can be added only once and the keys would never change dynamically to my knowledge, hence I don't see why compiling them on-the-fly is needed. According to the XSD scheme I don't really see a scenario when one of the <vevoFokonyvTipus> elements would be not needed but even then the field could be left empty (szamlazz.hu ignores empty fields I believe) or we can just put between IF-blocks as well.

If I'm overseeing something or there's some extra logic making this reasonable then I'm of course fine with the solution but could you please give me an explanation to better understand what's happening?

Thanks!

@theriverman
Copy link
Owner

Thanks for the PR, @kmate129 !
I've have a couple of questions about your implementation before merging it. Please see my inline comments in the PR.

@kmate129
Copy link
Author

kmate129 commented Mar 6, 2025

Thank you for the review. I have refactored my solution for both BuyerLedger and ItemLedger to use IF conditions. In terms of readability, it is indeed better than the dynamic approach.

The settlement_date_from and settlement_date_to fields are of type date and optional. I need to bind their rendering to an IF condition because, in the model I followed the schema for field types, treating them as strings. As a result, if left empty, a validation error occurs because an empty string does not match the date type required by xsd. Similarly, this applies to BuyerLedger.accounting_date.

For BuyerLedger.continuous_performance, if buyer.buyer_ledger is not set (None), the template engine will still try to access the continuous_performance field. However, since there is no BuyerLedger instance, the template engine generates an empty string. It also violates the xsd, handled by IF clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants