-
Notifications
You must be signed in to change notification settings - Fork 4
/
ordering.go
83 lines (76 loc) · 3.38 KB
/
ordering.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package bill
import (
"github.com/invopop/gobl/cal"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/uuid"
"github.com/invopop/validation"
"github.com/invopop/validation/is"
)
// Ordering provides additional information about the ordering process including references
// to other documents and alternative parties involved in the order-to-delivery process.
type Ordering struct {
// Identifier assigned by the customer or buyer for internal routing purposes.
Code string `json:"code,omitempty" jsonschema:"title=Code"`
// Any additional Codes, IDs, SKUs, or other regional or custom
// identifiers that may be used to identify the order.
Identities []*org.Identity `json:"identities,omitempty" jsonschema:"title=Identities"`
// Period of time that the invoice document refers to often used in addition to the details
// provided in the individual line items.
Period *cal.Period `json:"period,omitempty" jsonschema:"title=Period"`
// Project this invoice refers to.
Project *DocumentReference `json:"project,omitempty" jsonschema:"title=Project"`
// The identification of a contract.
Contract *DocumentReference `json:"contract,omitempty" jsonschema:"title=Contract"`
// Purchase order issued by the customer or buyer.
Purchase *DocumentReference `json:"purchase,omitempty" jsonschema:"title=Purchase Order"`
// Sales order issued by the supplier or seller.
Sale *DocumentReference `json:"sale,omitempty" jsonschema:"title=Sales Order"`
// Receiving Advice.
Receiving *DocumentReference `json:"receiving,omitempty" jsonschema:"title=Receiving Advice"`
// Despatch advice.
Despatch *DocumentReference `json:"despatch,omitempty" jsonschema:"title=Despatch Advice"`
// Tender advice, the identification of the call for tender or lot the invoice relates to.
Tender *DocumentReference `json:"tender,omitempty" jsonschema:"title=Tender Advice"`
// Party who is responsible for making the purchase, but is not responsible
// for handling taxes.
Buyer *org.Party `json:"buyer,omitempty" jsonschema:"title=Buyer"`
// Party who is selling the goods but is not responsible for taxes like the
// supplier.
Seller *org.Party `json:"seller,omitempty" jsonschema:"title=Seller"`
}
// DocumentReference provides a link to a existing document.
type DocumentReference struct {
// Unique ID copied from the source document.
UUID uuid.UUID `json:"uuid,omitempty" jsonschema:"title=UUID"`
// Series the reference document belongs to.
Series string `json:"series,omitempty" jsonschema:"title=Series"`
// Source document's code or other identifier.
Code string `json:"code,omitempty" jsonschema:"title=Code"`
// Link to the source document.
URL string `json:"url,omitempty" jsonschema:"title=URL,format=uri"`
}
// Validate the ordering details.
func (o *Ordering) Validate() error {
return validation.ValidateStruct(o,
validation.Field(&o.Identities),
validation.Field(&o.Project),
validation.Field(&o.Contract),
validation.Field(&o.Purchase),
validation.Field(&o.Sale),
validation.Field(&o.Receiving),
validation.Field(&o.Despatch),
validation.Field(&o.Tender),
validation.Field(&o.Buyer),
validation.Field(&o.Seller),
)
}
// Validate ensures the Document Reference looks correct.
func (dr *DocumentReference) Validate() error {
return validation.ValidateStruct(dr,
validation.Field(&dr.UUID),
validation.Field(&dr.Code,
validation.Match(InvoiceCodeRegexp),
),
validation.Field(&dr.URL, is.URL),
)
}