Skip to content

Commit

Permalink
Merge pull request #377 from invopop/pt-common-tags
Browse files Browse the repository at this point in the history
PT: Fix invoice tags
  • Loading branch information
samlown authored Sep 30, 2024
2 parents 08acd0a + 54d92f4 commit 60d69b2
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 38 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to GOBL will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). See also the [GOBL versions](https://docs.gobl.org/overview/versions) documentation site for more details.

## [v0.200.1]

### Fixed

- `pt`: moving invoice tags from saft addon to regime, ensure defaults present.

## [v0.200.0]

Another ~~significant~~ epic release. Introducing "add-ons" which move the normalization and validation rules from Tax Regimes to specific packages that need to be enabled inside a document to be used.
Expand Down
3 changes: 0 additions & 3 deletions addons/pt/saft/saft.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ func newAddon() *tax.AddonDef {
i18n.EN: "Portugal SAF-T",
},
Extensions: extensions,
Tags: []*tax.TagSet{
invoiceTags,
},
Normalizer: normalize,
Scenarios: scenarios,
Validator: validate,
Expand Down
22 changes: 2 additions & 20 deletions addons/pt/saft/scenarios.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,14 @@ package saft
import (
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/i18n"
"github.com/invopop/gobl/regimes/pt"
"github.com/invopop/gobl/tax"
)

// Invoice type tags
const (
TagInvoiceReceipt cbc.Key = "invoice-receipt"
)

var scenarios = []*tax.ScenarioSet{
invoiceScenarios,
}

var invoiceTags = &tax.TagSet{
Schema: bill.ShortSchemaInvoice,
List: []*cbc.KeyDefinition{
{
Key: TagInvoiceReceipt,
Name: i18n.String{
i18n.EN: "Invoice-receipt",
i18n.PT: "Fatura-recibo",
},
},
},
}

var invoiceScenarios = &tax.ScenarioSet{
Schema: bill.ShortSchemaInvoice,
List: []*tax.Scenario{
Expand All @@ -52,7 +34,7 @@ var invoiceScenarios = &tax.ScenarioSet{
if !ok {
return false
}
return inv.HasTags(TagInvoiceReceipt) || inv.Totals.Paid()
return inv.HasTags(pt.TagInvoiceReceipt) || inv.Totals.Paid()
},
Ext: tax.Extensions{
ExtKeyInvoiceType: "FR",
Expand Down
14 changes: 0 additions & 14 deletions data/addons/pt-saft-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,6 @@
]
}
],
"tags": [
{
"schema": "bill/invoice",
"list": [
{
"key": "invoice-receipt",
"name": {
"en": "Invoice-receipt",
"pt": "Fatura-recibo"
}
}
]
}
],
"scenarios": [
{
"schema": "bill/invoice",
Expand Down
65 changes: 65 additions & 0 deletions data/regimes/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,71 @@
"time_zone": "Europe/Lisbon",
"country": "PT",
"currency": "EUR",
"tags": [
{
"schema": "bill/invoice",
"list": [
{
"key": "simplified",
"name": {
"de": "Vereinfachte Rechnung",
"en": "Simplified Invoice",
"es": "Factura Simplificada",
"it": "Fattura Semplificata"
},
"desc": {
"de": "Wird für B2C-Transaktionen verwendet, wenn die Kundendaten nicht verfügbar sind. Bitte wenden Sie sich an die örtlichen Behörden, um die Grenzwerte zu ermitteln.",
"en": "Used for B2C transactions when the client details are not available, check with local authorities for limits.",
"es": "Usado para transacciones B2C cuando los detalles del cliente no están disponibles, consulte con las autoridades locales para los límites.",
"it": "Utilizzato per le transazioni B2C quando i dettagli del cliente non sono disponibili, controllare con le autorità locali per i limiti."
}
},
{
"key": "reverse-charge",
"name": {
"de": "Umkehr der Steuerschuld",
"en": "Reverse Charge",
"es": "Inversión del Sujeto Pasivo",
"it": "Inversione del soggetto passivo"
}
},
{
"key": "self-billed",
"name": {
"de": "Rechnung durch den Leistungsempfänger",
"en": "Self-billed",
"es": "Facturación por el destinatario",
"it": "Autofattura"
}
},
{
"key": "customer-rates",
"name": {
"de": "Kundensätze",
"en": "Customer rates",
"es": "Tarifas aplicables al destinatario",
"it": "Aliquote applicabili al destinatario"
}
},
{
"key": "partial",
"name": {
"de": "Teilweise",
"en": "Partial",
"es": "Parcial",
"it": "Parziale"
}
},
{
"key": "invoice-receipt",
"name": {
"en": "Invoice-receipt",
"pt": "Fatura-recibo"
}
}
]
}
],
"extensions": [
{
"key": "pt-region",
Expand Down
20 changes: 20 additions & 0 deletions regimes/pt/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@ package pt

import (
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/i18n"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/tax"
"github.com/invopop/validation"
)

// Invoice type tags
const (
TagInvoiceReceipt cbc.Key = "invoice-receipt"
)

var invoiceTags = &tax.TagSet{
Schema: bill.ShortSchemaInvoice,
List: []*cbc.KeyDefinition{
{
Key: TagInvoiceReceipt,
Name: i18n.String{
i18n.EN: "Invoice-receipt",
i18n.PT: "Fatura-recibo",
},
},
},
}

type invoiceValidator struct {
inv *bill.Invoice
}
Expand Down
9 changes: 9 additions & 0 deletions regimes/pt/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/invopop/gobl/cal"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/pt"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -51,6 +52,14 @@ func TestValidInvoice(t *testing.T) {
require.NoError(t, inv.Validate())
}

func TestValidSimplifiedInvoice(t *testing.T) {
inv := validInvoice()
inv.SetTags(tax.TagSimplified, pt.TagInvoiceReceipt)
inv.Customer = nil
require.NoError(t, inv.Calculate())
require.NoError(t, inv.Validate())
}

func TestLineValidation(t *testing.T) {
inv := validInvoice()
inv.Lines[0].Quantity = num.MakeAmount(-1, 0)
Expand Down
4 changes: 4 additions & 0 deletions regimes/pt/pt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/currency"
"github.com/invopop/gobl/i18n"
"github.com/invopop/gobl/regimes/common"
"github.com/invopop/gobl/tax"
)

Expand Down Expand Up @@ -42,6 +43,9 @@ func New() *tax.RegimeDef {
Extensions: extensionKeys,
Validator: Validate,
Normalizer: Normalize,
Tags: []*tax.TagSet{
common.InvoiceTags().Merge(invoiceTags),
},
Corrections: []*tax.CorrectionDefinition{
{
Schema: bill.ShortSchemaInvoice,
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type Version string

// VERSION is the current version of the GOBL library.
const VERSION Version = "v0.200.0"
const VERSION Version = "v0.200.1"

// Semver parses and returns semver
func (v Version) Semver() *semver.Version {
Expand Down

0 comments on commit 60d69b2

Please sign in to comment.