-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from appuio/feat/compat-mode
Add compatibility mode for creating odoo16 sales orders using odoo8 IDs
- Loading branch information
Showing
4 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,37 @@ import ( | |
odooclient "github.com/appuio/go-odoo" | ||
) | ||
|
||
func TestCreateCompat(t *testing.T) { | ||
ctrl, mock, subject := createStorageCompat(t) | ||
defer ctrl.Finish() | ||
|
||
tn := time.Now() | ||
st, _ := time.Parse(time.RFC3339, "2023-04-18T14:07:55Z") | ||
statusTime := st.Local() | ||
|
||
gomock.InOrder( | ||
mock.EXPECT().FindResPartners(gomock.Any(), gomock.Any()).Return(&odooclient.ResPartners{{ | ||
Id: odooclient.NewInt(456), | ||
CreateDate: odooclient.NewTime(tn), | ||
ParentId: odooclient.NewMany2One(123, ""), | ||
Email: odooclient.NewString("[email protected], [email protected]"), | ||
VshnControlApiMetaStatus: odooclient.NewString("{\"conditions\":[{\"type\":\"ConditionFoo\",\"status\":\"False\",\"lastTransitionTime\":\"" + statusTime.Format(time.RFC3339) + "\",\"reason\":\"Whatever\",\"message\":\"Hello World\"}]}"), | ||
}}, nil), | ||
mock.EXPECT().CreateSaleOrder(gomock.Any()).Return(int64(149), nil), | ||
) | ||
|
||
soid, err := subject.CreateSaleOrder(organizationv1.Organization{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "myorg", | ||
}, | ||
Spec: organizationv1.OrganizationSpec{ | ||
BillingEntityRef: "be-123", | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
assert.Equal(t, "149", soid) | ||
} | ||
|
||
func TestCreate(t *testing.T) { | ||
ctrl, mock, subject := createStorage(t) | ||
defer ctrl.Finish() | ||
|
@@ -48,7 +79,7 @@ func TestCreate(t *testing.T) { | |
} | ||
|
||
func TestGet(t *testing.T) { | ||
ctrl, mock, subject := createStorage(t) | ||
ctrl, mock, subject := createStorageCompat(t) | ||
defer ctrl.Finish() | ||
|
||
gomock.InOrder( | ||
|
@@ -73,6 +104,43 @@ func TestGet(t *testing.T) { | |
assert.Equal(t, "SO149", soid) | ||
} | ||
|
||
func TestCreateAttributesCompat(t *testing.T) { | ||
ctrl, mock, subject := createStorageCompat(t) | ||
defer ctrl.Finish() | ||
|
||
tn := time.Now() | ||
st, _ := time.Parse(time.RFC3339, "2023-04-18T14:07:55Z") | ||
statusTime := st.Local() | ||
|
||
gomock.InOrder( | ||
mock.EXPECT().FindResPartners(gomock.Any(), gomock.Any()).Return(&odooclient.ResPartners{{ | ||
Id: odooclient.NewInt(456), | ||
CreateDate: odooclient.NewTime(tn), | ||
ParentId: odooclient.NewMany2One(123, ""), | ||
Email: odooclient.NewString("[email protected], [email protected]"), | ||
VshnControlApiMetaStatus: odooclient.NewString("{\"conditions\":[{\"type\":\"ConditionFoo\",\"status\":\"False\",\"lastTransitionTime\":\"" + statusTime.Format(time.RFC3339) + "\",\"reason\":\"Whatever\",\"message\":\"Hello World\"}]}"), | ||
}}, nil), | ||
mock.EXPECT().CreateSaleOrder(SaleOrderMatcher{ | ||
PartnerId: int64(123), | ||
PartnerInvoiceId: int64(456), | ||
State: "sale", | ||
ClientOrderRef: "client-ref (myorg)", | ||
InternalNote: "internal-note", | ||
}).Return(int64(149), nil), | ||
) | ||
|
||
soid, err := subject.CreateSaleOrder(organizationv1.Organization{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "myorg", | ||
}, | ||
Spec: organizationv1.OrganizationSpec{ | ||
BillingEntityRef: "be-123", | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
assert.Equal(t, "149", soid) | ||
} | ||
|
||
func TestCreateAttributes(t *testing.T) { | ||
ctrl, mock, subject := createStorage(t) | ||
defer ctrl.Finish() | ||
|
@@ -126,6 +194,20 @@ func (s SaleOrderMatcher) String() string { | |
return fmt.Sprintf("{PartnerId:%d PartnerInvoiceId:%d State:%s ClientOrderRef:%s InternalNote:%s}", s.PartnerId, s.PartnerInvoiceId, s.State, s.ClientOrderRef, s.InternalNote) | ||
} | ||
|
||
func createStorageCompat(t *testing.T) (*gomock.Controller, *mock_saleorder.MockOdoo16Client, saleorder.SaleOrderStorage) { | ||
ctrl := gomock.NewController(t) | ||
mock := mock_saleorder.NewMockOdoo16Client(ctrl) | ||
|
||
return ctrl, mock, saleorder.NewOdoo16StorageFromClient( | ||
mock, | ||
&saleorder.Odoo16Options{ | ||
SaleOrderClientReferencePrefix: "client-ref", | ||
SaleOrderInternalNote: "internal-note", | ||
Odoo8CompatibilityMode: true, | ||
}, | ||
) | ||
} | ||
|
||
func createStorage(t *testing.T) (*gomock.Controller, *mock_saleorder.MockOdoo16Client, saleorder.SaleOrderStorage) { | ||
ctrl := gomock.NewController(t) | ||
mock := mock_saleorder.NewMockOdoo16Client(ctrl) | ||
|
@@ -135,6 +217,7 @@ func createStorage(t *testing.T) (*gomock.Controller, *mock_saleorder.MockOdoo16 | |
&saleorder.Odoo16Options{ | ||
SaleOrderClientReferencePrefix: "client-ref", | ||
SaleOrderInternalNote: "internal-note", | ||
Odoo8CompatibilityMode: false, | ||
}, | ||
) | ||
} |