Skip to content

feat(invoice)!: preserve ZATCA model fields - #53

Merged
mqqz merged 10 commits into
mainfrom
feat/invoice-model-coverage
Oct 19, 2026
Merged

mqqz merged 10 commits into
mainfrom
feat/invoice-model-coverage

Conversation

@mqqz

@mqqz mqqz commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Description

Invoice import could drop buyer details, delivery dates and VAT exemption metadata. Construction also lacked line adjustments, price bases and prepayment references.

Add those fields across the Rust model and shipped bindings. Accepted supplied monetary amounts drive serialization and downstream totals; inconsistent totals return errors. An optional line builder keeps ordinary line construction unchanged.

Breaking API changes include credit/debit invoice variants, optional party addresses and repeated identifiers/instructions. The implementation contract records replacement APIs and supported XML limits. Unsupported UBL content can still be dropped during reconstruction.

Testing

  • Full workspace tests and Clippy; live API calls excluded.
  • Source-to-output tests for all 150 pinned ZATCA dictionary rows.
  • All 11 refreshed official SDK parity cases.
  • C/C++, Python, JavaScript, .NET and Kotlin/Java checks, plus generated-binding drift checks.

Live ZATCA acceptance was not tested. Rebased onto the signed-XML hash fix in #52 and retained its regressions.

Checklist

  • Relevant tests and documentation updated
  • Formatting and warning checks passed
  • Changes reviewed
  • Breaking API changes documented; version bump deferred to release

mqqz added 3 commits October 19, 2026 18:10
Preserve optional fields and accepted monetary values across Rust, XML
and every shipped binding. Include matching SDK fixtures to check
serialization changes.

BREAKING CHANGE: credit/debit variants no longer embed references;
party addresses are optional and identifiers/instructions are lists.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T16:19:04.799814Z 0a0a098 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Reject negative imported discounts and missing required line VAT rates.
Preserve omitted out-of-scope adjustment rates and repeated VAT
classifications in percentage adjustments. Expose province in Python.

Add constructor, source-XML and FFI ownership regressions. Keep the
coverage threshold unchanged.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b991dfd4b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1510 to +1512
let utc = time.ends_with('Z');
let time = NaiveTime::parse_from_str(time.strip_suffix('Z').unwrap_or(time), "%H:%M:%S")
.map_err(|e| ParseError::InvalidValue {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle midnight before parsing with NaiveTime

When an invoice has the valid boundary time 24:00:00 or 24:00:00Z, this call rejects it because Chrono's NaiveTime only accepts hours through 23. The same change explicitly accepts these values in InvoiceTime::parse, so billing-reference times round-trip while the root cbc:IssueTime makes parse_finalized_invoice_xml fail; normalize midnight to the following day's 00:00:00 before constructing the UTC timestamp while retaining the original issue fields.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa6ac0d242

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread fatoora-core/src/invoice/builder.rs Outdated
self
}
pub fn payment_means(mut self, value: super::PaymentMeans) -> Self {
self.payment_means.push(value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reuse the placeholder when appending payment means

When payment_instruction() is called before this method, it creates a first PaymentMeans entry with an empty code; appending a valid entry here leaves that placeholder in the collection, and build() rejects it as an empty PaymentMeansCode. This affects the new bindings directly because InvoiceBuilder::new_with_reference calls payment_instruction() internally, so following it with the new add_payment_means() API cannot produce an invoice unless callers also know to invoke the legacy set_payment_means_code().

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94e76a2e90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bindings/python/fatoora/api.py Outdated
Comment on lines +898 to +901
b.set_vat_rate(item.vat_rate)
b.set_vat_category(item.vat_category)
b.set_line_net_amount(item.total_amount)
b.set_line_vat_amount(item.vat_amount)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve absent line tax fields when re-adding items

When item comes from invoice.line_item() for imported XML that omits an out-of-scope line's cbc:Percent, its line cac:TaxTotal, or its cbc:RoundingAmount, these unconditional setters reconstruct the item as though all three fields were present. The Python InvoiceLineItem value does not expose the corresponding omission flags, so builder.add_item(parsed.line_item(0)) silently inserts fields that the parser otherwise promises to preserve; carry those presence bits through the facade and only invoke the setters when the source field was present.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a0a098b63

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bindings/c/fatoora.h
char **out,
FatooraError **error);
void fatoora_invoice_totals_free(FatooraInvoiceTotals *self);
FatooraStatus fatoora_line_item_builder_set_tax_total_present(FatooraLineItemBuilder *self,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Expose a constructor for the C line-item builder

The public C facade declares every setter and build operation for FatooraLineItemBuilder, but neither fatoora.h nor fatoora.c exposes a function that creates one, and no other facade function returns this handle. Consequently C callers cannot use any of the new line builder APIs needed for adjustments, base quantities, supplied totals, or omission controls; add a facade constructor wrapping fatoora_LineItemBuilder_new.

Useful? React with 👍 / 👎.

Comment on lines +1013 to +1018
#[serde(default)]
omitted_tax_amount: bool,
#[serde(default)]
omitted_gross_amount: bool,
#[serde(default)]
omitted_vat_rate: bool,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate deserialized line omission flags

Because LineItem publicly derives Deserialize, callers can deserialize a line with omitted_tax_amount: true while retaining a nonzero vat_amount or tax subtotals, or set omitted_vat_rate for a standard-rated line, and then pass it to InvoiceBuilder::line_item. InvoiceBuilder::build does not revalidate these new flags, so serialization can omit required tax/rate elements and produce XML that this parser rejects; enforce the same omission invariants applied by LineItemBuilder::build when finalizing arbitrary LineItem values.

Useful? React with 👍 / 👎.

@mqqz
mqqz merged commit 8b9fb67 into main Oct 19, 2026
33 checks passed
@mqqz
mqqz deleted the feat/invoice-model-coverage branch October 19, 2026 20:14
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.

1 participant