-
Notifications
You must be signed in to change notification settings - Fork 3
Solve wrong percentage mapping #14
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the wrong percentage mapping from GOBL to UBL by switching from using the Base() method to the Amount() method when mapping percentage values, as per the official mapping documentation.
- Updates percentage conversion logic in lines.go, charges.go, and related discount mappings.
- Adjusts test assertions in lines_test.go and charges_test.go to reflect the corrected mapping values.
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lines_test.go | Updated test assertions to expect corrected multiplier values and amounts. |
| lines.go | Modified percentage mapping logic to use Amount() instead of Base(). |
| charges_test.go | Adjusted test expectations for multiplier factor in discount charges. |
| charges.go | Updated percentage conversion from Base() to Amount() for both charge and discount flows. |
Files not reviewed (1)
- test/data/convert/invoice-without-buyers-tax-id.json: Language not supported
Comments suppressed due to low confidence (3)
charges_test.go:26
- Confirm that the expected multiplier factor value in the test is aligned with the updated percentage mapping logic, ensuring full coverage of the new behavior.
assert.Equal(t, "5", *doc.InvoiceLines[0].AllowanceCharge[0].MultiplierFactorNumeric)
lines.go:176
- The conversion logic has been updated from Base() to Amount(), which should now correctly map percentages according to the documentation. Please verify that this change consistently reflects the intended percentage format across all usages in line charges.
p := ch.Percent.Amount().String()
charges.go:49
- Ensure that the updated conversion from Base() to Amount() properly handles percentage mapping for charges in line with the new specification.
p := ch.Percent.Amount().String()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Take a look at CII for a different approach, I used Percent.StringWithoutSymbol().
samlown
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? What is the source of this change?
| <cac:AllowanceCharge> | ||
| <cbc:ChargeIndicator>false</cbc:ChargeIndicator> | ||
| <cbc:MultiplierFactorNumeric>0.05</cbc:MultiplierFactorNumeric> | ||
| <cbc:MultiplierFactorNumeric>5</cbc:MultiplierFactorNumeric> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure about this? Multiplier factor I'd assume means a factor to apply from a percentage, so get 5% of something, you multiple by a factor if 0.05.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it also didn't make sense, but I was sending an invoice with a 50% discount and receiving a 0.5% discount. I checked it and it is stated here that 20% should be 20: https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-invoice/cac-AllowanceCharge/cbc-MultiplierFactorNumeric/#:~:text=To%20state%2020%25%2C%20use%20value%2020.
However, when checking this example (https://docs.oasis-open.org/ubl/os-UBL-2.1/xml/UBL-Invoice-2.1-Example.xml) it appears to be as you say
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the error isn't there it is in how we convert back from the UBL to GOBL, because the approach is different from GOBL to UBL and from UBL to GOBL
|
So we have a bit of extra context here... this is still an issue. It turns out that standard UBL has a different approach to Peppol UBL. This change shouldn't just be a blanket switch, it needs to be adjusted according to the document's profile. |
The percentage from GOBL to UBL was being wrongly mapped.
Before:
Now:
Here it is explained how to map it: https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-invoice/cac-AllowanceCharge/cbc-MultiplierFactorNumeric/