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

Defining common invoice tags, simplified invoice validation moved up #218

Merged
merged 8 commits into from
Nov 23, 2023
7 changes: 3 additions & 4 deletions bill/invoice.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ import (
"github.com/invopop/gobl/currency"
"github.com/invopop/gobl/internal"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/common"
"github.com/invopop/gobl/schema"
"github.com/invopop/gobl/tax"
"github.com/invopop/gobl/uuid"
@@ -142,7 +141,7 @@ func (inv *Invoice) ValidateWithContext(ctx context.Context) error {
validation.Field(&inv.Customer,
// Customer is not required for simplified invoices.
validation.When(
!inv.Tax.ContainsTag(common.TagSimplified),
!inv.Tax.ContainsTag(tax.TagSimplified),
validation.Required,
),
),
@@ -449,7 +448,7 @@ func (inv *Invoice) calculate(r *tax.Regime, tID *tax.Identity) error {
}

// Finally calculate the total with *all* the taxes.
if inv.Tax != nil && inv.Tax.ContainsTag(common.TagReverseCharge) {
if inv.Tax != nil && inv.Tax.ContainsTag(tax.TagReverseCharge) {
t.Tax = zero
} else {
t.Tax = t.Taxes.PreciseSum()
@@ -501,7 +500,7 @@ func calculateComplements(comps []*schema.Object) error {

func (inv *Invoice) determineTaxIdentity() *tax.Identity {
if inv.Tax != nil {
if inv.Tax.ContainsTag(common.TagCustomerRates) {
if inv.Tax.ContainsTag(tax.TagCustomerRates) {
if inv.Customer == nil {
return nil
}
5 changes: 2 additions & 3 deletions bill/invoice_correct_test.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ import (
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/co"
"github.com/invopop/gobl/regimes/common"
"github.com/invopop/gobl/regimes/es"
"github.com/invopop/gobl/tax"
"github.com/invopop/jsonschema"
@@ -194,7 +193,7 @@ func testInvoiceESForCorrection(t *testing.T) *bill.Invoice {
Series: "TEST",
Code: "123",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
@@ -283,7 +282,7 @@ func testInvoiceCOForCorrection(t *testing.T) *bill.Invoice {
Series: "TEST",
Code: "123",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
21 changes: 10 additions & 11 deletions bill/invoice_test.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ import (
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/pay"
"github.com/invopop/gobl/regimes/common"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -32,7 +31,7 @@ func TestInvoiceRegimeCurrency(t *testing.T) {
Taxes: tax.Set{
{
Category: "VAT",
Rate: common.TaxRateStandard,
Rate: tax.RateStandard,
},
},
},
@@ -164,7 +163,7 @@ func TestRemoveIncludedTax2(t *testing.T) {
i := &bill.Invoice{
Code: "123TEST",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
@@ -228,7 +227,7 @@ func TestRemoveIncludedTax3(t *testing.T) {
i := &bill.Invoice{
Code: "123TEST",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
@@ -321,7 +320,7 @@ func TestRemoveIncludedTax4(t *testing.T) {
i := &bill.Invoice{
Code: "123TEST",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
@@ -419,7 +418,7 @@ func TestRemoveIncludedTaxQuantity(t *testing.T) {
i := &bill.Invoice{
Code: "123TEST",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
@@ -493,7 +492,7 @@ func TestRemoveIncludedTaxDeep(t *testing.T) {
i := &bill.Invoice{
Code: "123TEST",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
@@ -574,7 +573,7 @@ func TestRemoveIncludedTaxDeep2(t *testing.T) {
i := &bill.Invoice{
Code: "123TEST",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
@@ -686,7 +685,7 @@ func TestCalculate(t *testing.T) {
i := &bill.Invoice{
Code: "123TEST",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
@@ -760,7 +759,7 @@ func TestValidation(t *testing.T) {
Currency: currency.EUR,
IssueDate: cal.MakeDate(2022, 6, 13),
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
Name: "Test Supplier",
@@ -806,7 +805,7 @@ func baseInvoice(t *testing.T, lines ...*bill.Line) *bill.Invoice {
i := &bill.Invoice{
Code: "123TEST",
Tax: &bill.Tax{
PricesInclude: common.TaxCategoryVAT,
PricesInclude: tax.CategoryVAT,
},
Supplier: &org.Party{
TaxID: &tax.Identity{
105 changes: 0 additions & 105 deletions build/schemas/regimes/mx/food-vouchers.json
cavalle marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Loading