Skip to content

Commit 15aa758

Browse files
committed
feat(sweden): use party validation instead of invoice
1 parent 7de2ee5 commit 15aa758

File tree

4 files changed

+34
-114
lines changed

4 files changed

+34
-114
lines changed

regimes/se/invoices.go

Lines changed: 0 additions & 111 deletions
This file was deleted.

regimes/se/invoices_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ func TestInvoiceValidation(t *testing.T) {
9393
require.NoError(t, inv.Validate())
9494
})
9595

96+
// FIX: currently failing since we don't have a way to separate Supplier and Customer
97+
// with current implementation.
9698
t.Run("missing supplier tax ID", func(t *testing.T) {
9799
t.Parallel()
98100
inv := testInvoiceStandard(t)

regimes/se/org_parties.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package se
2+
3+
import (
4+
"github.com/invopop/gobl/org"
5+
"github.com/invopop/validation"
6+
)
7+
8+
// validateOrgParty checks the organization party fulfills Swedish requirements.
9+
func validateOrgParty(value any) error {
10+
party, ok := value.(*org.Party)
11+
if !ok || party == nil {
12+
return nil
13+
}
14+
15+
// TO-DO: Find a way to validate that Suppliers must always include the Tax ID
16+
17+
return validation.ValidateStruct(party,
18+
// Names are always required.
19+
validation.Field(&party.Name,
20+
validation.Required,
21+
validation.Skip,
22+
),
23+
// Addresses are required, but needn't be Swedish. It could be 2 foreign companies
24+
// where the supplier is registered for VAT in Sweden and the operation happens in Sweden.
25+
validation.Field(&party.Addresses,
26+
validation.Required,
27+
validation.Skip,
28+
),
29+
)
30+
}

regimes/se/se.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package se
33

44
import (
5-
"github.com/invopop/gobl/bill"
65
"github.com/invopop/gobl/currency"
76
"github.com/invopop/gobl/i18n"
87
"github.com/invopop/gobl/l10n"
@@ -43,12 +42,12 @@ func New() *tax.RegimeDef {
4342
// Validate checks the document type and determines if it can be validated.
4443
func Validate(doc any) error {
4544
switch obj := doc.(type) {
46-
case *bill.Invoice:
47-
return validateInvoice(obj)
4845
case *tax.Identity:
4946
return validateTaxIdentity(obj)
5047
case *org.Identity:
5148
return validateOrgIdentity(obj)
49+
case *org.Party:
50+
return validateOrgParty(obj)
5251
}
5352
return nil
5453
}

0 commit comments

Comments
 (0)