Skip to content

Commit

Permalink
Rename 'method' back to 'correction_method' in preceding context
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Sep 18, 2023
1 parent 3eb3bd4 commit 6d9fc6d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 26 deletions.
20 changes: 10 additions & 10 deletions bill/invoice_correct.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ func (inv *Invoice) Correct(opts ...schema.Option) error {

// Copy and prepare the basic fields
pre := &Preceding{
UUID: inv.UUID,
Series: inv.Series,
Code: inv.Code,
IssueDate: inv.IssueDate.Clone(),
Reason: o.Reason,
Method: o.Method,
Changes: o.Changes,
UUID: inv.UUID,
Series: inv.Series,
Code: inv.Code,
IssueDate: inv.IssueDate.Clone(),
Reason: o.Reason,
CorrectionMethod: o.Method,
Changes: o.Changes,
}
inv.UUID = nil
inv.Series = ""
Expand Down Expand Up @@ -247,11 +247,11 @@ func (inv *Invoice) validatePrecedingData(o *CorrectionOptions, cd *tax.Correcti
}

if len(cd.Methods) > 0 {
if pre.Method == cbc.KeyEmpty {
if pre.CorrectionMethod == cbc.KeyEmpty {
return errors.New("missing correction method")
}
if !cd.HasMethod(pre.Method) {
return fmt.Errorf("invalid correction method: %v", pre.Method)
if !cd.HasMethod(pre.CorrectionMethod) {
return fmt.Errorf("invalid correction method: %v", pre.CorrectionMethod)
}
}

Expand Down
2 changes: 1 addition & 1 deletion bill/invoice_correct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestInvoiceCorrect(t *testing.T) {
pre = i.Preceding[0]
require.Len(t, pre.Stamps, 1)
assert.Equal(t, pre.Stamps[0].Provider, co.StampProviderDIANCUDE)
assert.Equal(t, pre.Method, co.CorrectionMethodKeyRevoked)
assert.Equal(t, pre.CorrectionMethod, co.CorrectionMethodKeyRevoked)
}

func TestCorrectWithOptions(t *testing.T) {
Expand Down
10 changes: 3 additions & 7 deletions bill/preceding.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Preceding struct {
// Seals of approval from other organisations that may need to be listed.
Stamps []*head.Stamp `json:"stamps,omitempty" jsonschema:"title=Stamps"`
// Tax regime specific key reflecting the method used to correct the preceding invoice.
Method cbc.Key `json:"method,omitempty" jsonschema:"title=Method"`
CorrectionMethod cbc.Key `json:"correction_method,omitempty" jsonschema:"title=Correction Method"`
// Tax regime specific keys reflecting what has been changed from the previous invoice.
Changes []cbc.Key `json:"changes,omitempty" jsonschema:"title=Changes"`
// Tax period in which the previous invoice had an effect required by some tax regimes and formats.
Expand All @@ -40,18 +40,14 @@ type Preceding struct {
func (p *Preceding) UnmarshalJSON(data []byte) error {
type Alias Preceding
aux := &struct {
CorrectionMethod cbc.Key `json:"correction_method,omitempty"`
Corrections []cbc.Key `json:"corrections,omitempty"`
Corrections []cbc.Key `json:"corrections,omitempty"`
*Alias
}{
Alias: (*Alias)(p),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
if aux.CorrectionMethod != cbc.KeyEmpty {
p.Method = aux.CorrectionMethod
}
if len(aux.Corrections) != 0 {
p.Changes = aux.Corrections
}
Expand All @@ -66,7 +62,7 @@ func (p *Preceding) Validate() error {
validation.Field(&p.Code, validation.Required),
validation.Field(&p.IssueDate, cal.DateNotZero()),
validation.Field(&p.Stamps),
validation.Field(&p.Method),
validation.Field(&p.CorrectionMethod),
validation.Field(&p.Changes),
validation.Field(&p.Period),
validation.Field(&p.Meta),
Expand Down
2 changes: 1 addition & 1 deletion bill/preceding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ func TestPrecedingJSONMigration(t *testing.T) {
p := new(bill.Preceding)
err := p.UnmarshalJSON(data)
assert.NoError(t, err)
assert.Equal(t, "foo", p.Method.String())
assert.Equal(t, "foo", p.CorrectionMethod.String())
assert.Equal(t, "bar", p.Changes[0].String())
}
2 changes: 1 addition & 1 deletion regimes/co/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (v *invoiceValidator) preceding(value interface{}) error {
return nil
}
return validation.ValidateStruct(obj,
validation.Field(&obj.Method, validation.Required, isValidCorrectionMethodKey),
validation.Field(&obj.CorrectionMethod, validation.Required, isValidCorrectionMethodKey),
validation.Field(&obj.Reason, validation.Required),
)
}
10 changes: 5 additions & 5 deletions regimes/co/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func creditNote() *bill.Invoice {
IssueDate: cal.MakeDate(2022, 12, 29),
Preceding: []*bill.Preceding{
{
Code: "TEST",
IssueDate: cal.NewDate(2022, 12, 27),
Method: co.CorrectionMethodKeyRevoked,
Code: "TEST",
IssueDate: cal.NewDate(2022, 12, 27),
CorrectionMethod: co.CorrectionMethodKeyRevoked,
},
},
Supplier: &org.Party{
Expand Down Expand Up @@ -156,9 +156,9 @@ func TestBasicCreditNoteValidation(t *testing.T) {
require.NoError(t, err)
err = inv.Validate()
assert.NoError(t, err)
assert.Equal(t, inv.Preceding[0].Method, co.CorrectionMethodKeyRevoked)
assert.Equal(t, inv.Preceding[0].CorrectionMethod, co.CorrectionMethodKeyRevoked)

inv.Preceding[0].Method = "fooo"
inv.Preceding[0].CorrectionMethod = "fooo"
err = inv.Validate()
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "method: must be a valid value")
Expand Down
2 changes: 1 addition & 1 deletion regimes/es/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (v *invoiceValidator) preceding(value interface{}) error {
validation.Required,
validation.Each(isValidCorrectionKey),
),
validation.Field(&obj.Method,
validation.Field(&obj.CorrectionMethod,
validation.Required,
isValidCorrectionMethodKey,
),
Expand Down

0 comments on commit 6d9fc6d

Please sign in to comment.