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

Update BuyerReference/OrderReference #9

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion internal/gtou/ordering.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (c *Converter) newOrdering(o *bill.Ordering) error {
}

if o.Code != "" {
c.doc.OrderReference = &document.OrderReference{ID: string(o.Code)}
c.doc.BuyerReference = o.Code.String()
}

// If both ordering.seller and seller are present, the original seller is used
Expand Down Expand Up @@ -71,5 +71,12 @@ func (c *Converter) newOrdering(o *bill.Ordering) error {
}
}

if len(o.Purchases) > 0 {
purchase := o.Purchases[0]
c.doc.OrderReference = &document.OrderReference{
ID: purchase.Code.String(),
}
}

return nil
}
3 changes: 2 additions & 1 deletion internal/gtou/ordering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ func TestNewOrdering(t *testing.T) {
doc, err := newDocumentFrom("invoice-de-de.json")
require.NoError(t, err)

assert.Equal(t, "PO4711", doc.OrderReference.ID)
assert.Equal(t, "PO4711", doc.BuyerReference)
assert.Equal(t, "2013-03-10", *doc.InvoicePeriod[0].StartDate)
assert.Equal(t, "2013-04-10", *doc.InvoicePeriod[0].EndDate)
assert.Equal(t, "2013-05", doc.ContractDocumentReference[0].ID.Value)
assert.Equal(t, "PO4711", doc.OrderReference.ID)
assert.Equal(t, "3544", doc.ReceiptDocumentReference[0].ID.Value)
assert.Equal(t, "5433", doc.DespatchDocumentReference[0].ID.Value)

Expand Down
8 changes: 4 additions & 4 deletions internal/utog/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (c *Converter) getLines(doc *document.Invoice) error {
if err != nil {
return err
}

if docLine.InvoicedQuantity.UnitCode != "" {
line.Item.Unit = UnitFromUNECE(cbc.Code(docLine.InvoicedQuantity.UnitCode))
}
}

if len(docLine.Note) > 0 {
Expand All @@ -68,10 +72,6 @@ func (c *Converter) getLines(doc *document.Invoice) error {
})
}

if docLine.InvoicedQuantity.UnitCode != "" {
line.Item.Unit = UnitFromUNECE(cbc.Code(docLine.InvoicedQuantity.UnitCode))
}

line.Item.Identities = c.getIdentities(&docLine)

if docLine.Item.Description != nil {
Expand Down
12 changes: 10 additions & 2 deletions internal/utog/ordering.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
func (c *Converter) getOrdering(doc *document.Invoice) error {
ordering := &bill.Ordering{}

if doc.OrderReference != nil && doc.OrderReference.ID != "" {
ordering.Code = cbc.Code(doc.OrderReference.ID)
if doc.BuyerReference != "" {
ordering.Code = cbc.Code(doc.BuyerReference)
}

// GOBL does not currently support multiple periods, so only the first one is taken
Expand Down Expand Up @@ -42,6 +42,14 @@ func (c *Converter) getOrdering(doc *document.Invoice) error {
}
}

if doc.OrderReference != nil && doc.OrderReference.ID != "" {
ordering.Purchases = []*org.DocumentRef{
{
Code: cbc.Code(doc.OrderReference.ID),
},
}
}

if doc.ContractDocumentReference != nil {
ordering.Contracts = make([]*org.DocumentRef, 0)
for _, contractRef := range doc.ContractDocumentReference {
Expand Down
4 changes: 2 additions & 2 deletions internal/utog/ordering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestGetOrdering(t *testing.T) {
ordering := inv.Ordering
assert.NotNil(t, ordering)

assert.Equal(t, cbc.Code("123"), ordering.Code)
assert.Equal(t, "2013-06-01", ordering.Period.Start.String())
assert.Equal(t, "2013-06-30", ordering.Period.End.String())
assert.Equal(t, cbc.Code("Contract321"), ordering.Contracts[0].Code)
Expand All @@ -36,10 +35,11 @@ func TestGetOrdering(t *testing.T) {
ordering := inv.Ordering
assert.NotNil(t, ordering)

assert.Equal(t, cbc.Code("PO4711"), ordering.Code)
assert.Equal(t, cbc.Code("123"), ordering.Code)
assert.Equal(t, "2013-03-10", ordering.Period.Start.String())
assert.Equal(t, "2013-04-10", ordering.Period.End.String())
assert.Equal(t, cbc.Code("2013-05"), ordering.Contracts[0].Code)
assert.Equal(t, cbc.Code("PO4711"), ordering.Purchases[0].Code)
assert.Equal(t, cbc.Code("3544"), ordering.Receiving[0].Code)
assert.Equal(t, cbc.Code("5433"), ordering.Despatch[0].Code)
})
Expand Down
5 changes: 5 additions & 0 deletions test/data/gtou/invoice-de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
{
"code": "2013-05"
}
],
"purchases": [
{
"code": "PO4711"
}
],
"receiving": [
{
Expand Down
4 changes: 1 addition & 3 deletions test/data/gtou/out/correction-invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
<cbc:IssueDate>2024-02-15</cbc:IssueDate>
<cbc:InvoiceTypeCode>384</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cac:OrderReference>
<cbc:ID>XR-2024-2</cbc:ID>
</cac:OrderReference>
<cbc:BuyerReference>XR-2024-2</cbc:BuyerReference>
<cac:AccountingSupplierParty>
<cac:Party>
<cac:PostalAddress>
Expand Down
4 changes: 1 addition & 3 deletions test/data/gtou/out/credit-note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
<cbc:IssueDate>2024-02-14</cbc:IssueDate>
<cbc:InvoiceTypeCode>381</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cac:OrderReference>
<cbc:ID>XR-2024-4</cbc:ID>
</cac:OrderReference>
<cbc:BuyerReference>XR-2024-4</cbc:BuyerReference>
<cac:AccountingSupplierParty>
<cac:Party>
<cac:PostalAddress>
Expand Down
4 changes: 1 addition & 3 deletions test/data/gtou/out/invoice-complete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
<cbc:DueDate>2013-07-20</cbc:DueDate>
<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cbc:BuyerReference>PO4711</cbc:BuyerReference>
<cac:InvoicePeriod>
<cbc:StartDate>2013-03-10</cbc:StartDate>
<cbc:EndDate>2013-04-10</cbc:EndDate>
</cac:InvoicePeriod>
<cac:OrderReference>
<cbc:ID>PO4711</cbc:ID>
</cac:OrderReference>
<cac:DespatchDocumentReference>
<cbc:ID>5433</cbc:ID>
</cac:DespatchDocumentReference>
Expand Down
1 change: 1 addition & 0 deletions test/data/gtou/out/invoice-de-de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<cbc:IssueDate>2024-02-13</cbc:IssueDate>
<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cbc:BuyerReference>PO4711</cbc:BuyerReference>
<cac:InvoicePeriod>
<cbc:StartDate>2013-03-10</cbc:StartDate>
<cbc:EndDate>2013-04-10</cbc:EndDate>
Expand Down
4 changes: 1 addition & 3 deletions test/data/gtou/out/invoice-without-buyers-tax-id.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
<cbc:IssueDate>2024-02-13</cbc:IssueDate>
<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cac:OrderReference>
<cbc:ID>XR-2024-3</cbc:ID>
</cac:OrderReference>
<cbc:BuyerReference>XR-2024-3</cbc:BuyerReference>
<cac:AccountingSupplierParty>
<cac:Party>
<cac:PostalAddress>
Expand Down
4 changes: 1 addition & 3 deletions test/data/gtou/out/self-billed-invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
<cbc:DueDate>2013-07-20</cbc:DueDate>
<cbc:InvoiceTypeCode>389</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cac:OrderReference>
<cbc:ID>XR-2024-2</cbc:ID>
</cac:OrderReference>
<cbc:BuyerReference>XR-2024-2</cbc:BuyerReference>
<cac:AccountingSupplierParty>
<cac:Party>
<cac:PostalAddress>
Expand Down
6 changes: 3 additions & 3 deletions test/data/utog/out/ubl-example1.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "01933080-ae64-7397-82cb-6c42b0cea3da",
"uuid": "01945010-9afc-7abd-a7a6-eb89a9602993",
"dig": {
"alg": "sha256",
"val": "237a85d46aa33c97daf7498b302adb41c91dbac5670f1f985a0990f2a88fae5d"
"val": "247176b23f518434925ab9b87b11bd8fba225d4c5adc3175b206bde2be55057b"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"$regime": "NL",
"uuid": "01933080-ae64-73db-87e5-aa6d5a4afa2e",
"uuid": "01945010-9afc-7b02-8f90-67e81f28efc0",
"type": "standard",
"code": "12115118",
"issue_date": "2015-01-09",
Expand Down
7 changes: 3 additions & 4 deletions test/data/utog/out/ubl-example2.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "01933080-ae87-720b-a938-050d4dcc08ee",
"uuid": "01945010-9b1f-7f26-aff8-9d58d280843e",
"dig": {
"alg": "sha256",
"val": "322d80f327812218e0e09c6d05bd1f1fe0a90c8a2b54e0e81c230238354c7f1e"
"val": "618c16c2680a56426f988b02bea0a1dae1665c094625177cb9bdc9a6eab96b00"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"uuid": "01933080-ae87-726a-893e-fafd54752ff9",
"uuid": "01945010-9b20-7021-a4cf-d82d55145c89",
"type": "standard",
"code": "TOSL108",
"issue_date": "2013-06-30",
Expand Down Expand Up @@ -335,7 +335,6 @@
}
],
"ordering": {
"code": "123",
"period": {
"start": "2013-06-01",
"end": "2013-06-30"
Expand Down
6 changes: 3 additions & 3 deletions test/data/utog/out/ubl-example3.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "01933080-aea7-7a31-bdf1-f3069d5c7296",
"uuid": "01945010-9b42-7a52-9d86-2982e2ffba32",
"dig": {
"alg": "sha256",
"val": "18a28b751e92010dd88cf2bc902ca328c709464408d26540973cf72614d7f2a9"
"val": "81ca836c776ec30a00a536c4a86e94325c21c30ce12e2988fb933a4a638a0f29"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"uuid": "01933080-aea7-7a7f-8ddc-19039fad7255",
"uuid": "01945010-9b42-7a94-a51d-fac49928c902",
"type": "standard",
"code": "TOSL108",
"issue_date": "2013-04-10",
Expand Down
9 changes: 3 additions & 6 deletions test/data/utog/out/ubl-example4.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "01933080-aec6-7515-8cc6-9aa43bcbe8cb",
"uuid": "01945010-9b68-70e1-b391-2230e9ae30e3",
"dig": {
"alg": "sha256",
"val": "595c99b48a1e721c38966534cbb0cb14004428999235d4b9321184ebe2746f3f"
"val": "1972e6ad962dd85fc731c92fa2db949e1f324095d39a9ec7ed03a0304444f2bb"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"uuid": "01933080-aec6-7586-ba39-4f1268a33066",
"uuid": "01945010-9b68-7120-94cf-b61e6ea415d4",
"type": "standard",
"code": "TOSL110",
"issue_date": "2013-04-10",
Expand Down Expand Up @@ -142,9 +142,6 @@
"total": "2500.00"
}
],
"ordering": {
"code": "123"
},
"payment": {
"instructions": {
"key": "credit-transfer",
Expand Down
13 changes: 9 additions & 4 deletions test/data/utog/out/ubl-example5.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "01933080-aeee-7771-a3b3-d3643091ccf8",
"uuid": "01945010-9b8a-7e77-9ae3-767b2525687d",
"dig": {
"alg": "sha256",
"val": "1d6dc2bf5d288ebf4935c4d3e4ef7299d750234c8c925411c482eccb11dc5863"
"val": "70800dce7e3501f096af0904250057198e03534e0f17e4946fca1a4933b5ad79"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"uuid": "01933080-aeee-77c0-87ee-35fd6a8a03fe",
"uuid": "01945010-9b8a-7ea9-a4f8-893805efb822",
"type": "standard",
"code": "TOSL110",
"issue_date": "2013-04-10",
Expand Down Expand Up @@ -242,7 +242,7 @@
}
],
"ordering": {
"code": "PO4711",
"code": "123",
"period": {
"start": "2013-03-10",
"end": "2013-04-10"
Expand Down Expand Up @@ -308,6 +308,11 @@
"code": "2013-05"
}
],
"purchases": [
{
"code": "PO4711"
}
],
"receiving": [
{
"code": "3544"
Expand Down
6 changes: 3 additions & 3 deletions test/data/utog/out/ubl-example6.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "01933080-af0f-74b9-bc02-5b541d8f3bd8",
"uuid": "01945010-9bac-7948-9a98-2838347dba0f",
"dig": {
"alg": "sha256",
"val": "85bcc599f49deb0c68d6497fbcb90cbaf5b9eb5e967621c587d8ea2b2f9b5563"
"val": "dc44bf35636b83bc29f67e4cc1e30e8b7c25417c00507ae7ff8e331570f1dff8"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"uuid": "01933080-af0f-7501-905c-1f08dc0000b8",
"uuid": "01945010-9bac-79a3-b3cd-141d40e39fed",
"type": "standard",
"code": "TOSL110",
"issue_date": "2013-04-10",
Expand Down
14 changes: 9 additions & 5 deletions test/data/utog/out/ubl-example7.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "01933080-af31-7255-bf0e-d2c89e276daa",
"uuid": "01945010-9bcc-7f09-beb8-59d1350ec682",
"dig": {
"alg": "sha256",
"val": "92931d10c6e04f334bbe20efe7fcf8e9ae6fd4d940c29bf488a2dafcef8a6031"
"val": "335d01586f7a8f6b412a4c27f47ba35a7017e099d409390218ed0041736deb83"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"uuid": "01933080-af31-72b5-b6f3-412414f99f28",
"uuid": "01945010-9bcd-7002-88aa-7344d301b20d",
"type": "standard",
"code": "INVOICE_test_7",
"issue_date": "2013-03-11",
Expand Down Expand Up @@ -112,11 +112,15 @@
}
],
"ordering": {
"code": "Order_9988_x",
"period": {
"start": "2013-01-01",
"end": "2013-12-31"
}
},
"purchases": [
{
"code": "Order_9988_x"
}
]
},
"payment": {
"terms": {
Expand Down
6 changes: 3 additions & 3 deletions test/data/utog/out/ubl-example8.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "01933080-af57-75f0-9016-3338b6cd2caf",
"uuid": "01945010-9bef-7adf-a55a-19db3e4907dd",
"dig": {
"alg": "sha256",
"val": "c6939643f6a14cd7d96ae019f0558dc7dce9dee9a9a8c90cc00642a199a34709"
"val": "aba8c22d1657980391e49c06c9cf96a2300f802080bc4662b391434aa356dac7"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"$regime": "NL",
"uuid": "01933080-af57-762c-b7a8-beb8b4569e06",
"uuid": "01945010-9bef-7b2e-a7fa-415894efb234",
"type": "standard",
"code": "1100512149",
"issue_date": "2014-11-10",
Expand Down
Loading
Loading