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

Draft: PL regime #215

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions regimes/pl/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func (v *invoiceValidator) validate() error {
// Rectification state determined by Preceding value.
validation.Field(&inv.Type, validation.In(
bill.InvoiceTypeStandard,
bill.InvoiceTypeCorrective,
bill.InvoiceTypeProforma,
// bill.InvoiceTypeCorrective,
)),
// validation.Field(&inv.Preceding,
// validation.Each(validation.By(v.preceding)),
Expand Down Expand Up @@ -60,7 +59,18 @@ func (v *invoiceValidator) supplier(value interface{}) error {
tax.RequireIdentityCode,
validation.By(validatePolishTaxIdentity),
),
// TODO check if name exists
validation.Field(&obj.Name,
validation.When(
len(obj.People) == 0,
validation.Required,
),
),
validation.Field(&obj.People[0].Name,
validation.When(
obj.Name == "",
validation.Required,
),
),
Comment on lines +62 to +73
Copy link
Collaborator

Choose a reason for hiding this comment

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

This won't work as expected. Firstly and empty People array will cause a nil panic. An "org.Party" without a name will also not pass validation, so in effect the People array will never be checked.
I'm guessing the use-case here is for selling to individuals with tax details as opposed to companies. My proposal would be to just assume that the name is filled out, and optionally use the first "org.Person" from the people list, if available.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've merged this BTW with the https://github.com/invopop/gobl/tree/Risers-regime-pl branch, which you should now be able to access directly.

)
}

Expand All @@ -80,7 +90,18 @@ func (v *invoiceValidator) commercialCustomer(value interface{}) error {
obj.TaxID.Country.In(l10n.PL),
validation.By(validatePolishTaxIdentity),
), // TODO check if id is valid when other entity
// TODO check if name exists
),
validation.Field(&obj.Name,
validation.When(
len(obj.People) == 0,
validation.Required,
),
),
validation.Field(&obj.People[0].Name,
validation.When(
obj.Name == "",
validation.Required,
),
),
)
}
Expand Down