add method for getting financial report
This commit is contained in:
		@@ -160,7 +160,7 @@
 | 
				
			|||||||
- [ ] Report on products movement
 | 
					- [ ] Report on products movement
 | 
				
			||||||
- [ ] Returns report
 | 
					- [ ] Returns report
 | 
				
			||||||
- [ ] Shipment report
 | 
					- [ ] Shipment report
 | 
				
			||||||
- [ ] Financial report
 | 
					- [x] Financial report
 | 
				
			||||||
- [ ] Issue a report on discounted products
 | 
					- [ ] Issue a report on discounted products
 | 
				
			||||||
- [ ] Report on discounted products
 | 
					- [ ] Report on discounted products
 | 
				
			||||||
- [ ] List of reports on discounted products
 | 
					- [ ] List of reports on discounted products
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -148,3 +148,80 @@ func (c Reports) GetReportDetails(params *GetReportDetailsParams) (*GetReportDet
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return resp, nil
 | 
						return resp, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetFinancialReportParams struct {
 | 
				
			||||||
 | 
						// Report generation period
 | 
				
			||||||
 | 
						Date GetFinancialReportDatePeriod `json:"date"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Number of the page returned in the request
 | 
				
			||||||
 | 
						Page int64 `json:"page"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Number of items on the page
 | 
				
			||||||
 | 
						PageSize int64 `json:"page_size"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetFinancialReportDatePeriod struct {
 | 
				
			||||||
 | 
						// Date from which the report is calculated
 | 
				
			||||||
 | 
						From time.Time `json:"from"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Date up to which the report is calculated
 | 
				
			||||||
 | 
						To time.Time `json:"to"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetFinancialReportResponse struct {
 | 
				
			||||||
 | 
						core.CommonResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Method result
 | 
				
			||||||
 | 
						Result struct {
 | 
				
			||||||
 | 
							// Reports list
 | 
				
			||||||
 | 
							CashFlows []struct {
 | 
				
			||||||
 | 
								// Period data
 | 
				
			||||||
 | 
								Period struct {
 | 
				
			||||||
 | 
									// Period identifier
 | 
				
			||||||
 | 
									Id int64 `json:"id"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// Period start
 | 
				
			||||||
 | 
									Begin time.Time `json:"begin"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// Period end
 | 
				
			||||||
 | 
									End time.Time `json:"end"`
 | 
				
			||||||
 | 
								} `json:"period"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Sum of sold products prices
 | 
				
			||||||
 | 
								OrdersAmount float64 `json:"order_amount"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Sum of returned products prices
 | 
				
			||||||
 | 
								ReturnsAmount float64 `json:"returns_amount"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Ozon sales commission
 | 
				
			||||||
 | 
								CommissionAmount float64 `json:"commission_amount"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Additional services cost
 | 
				
			||||||
 | 
								ServicesAmount float64 `json:"services_amount"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Logistic services cost
 | 
				
			||||||
 | 
								ItemDeliveryAndReturnAmount float64 `json:"item_delivery_and_return_amount"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Code of the currency used to calculate the commissions
 | 
				
			||||||
 | 
								CurrencyCode string `json:"currency_code"`
 | 
				
			||||||
 | 
							} `json:"cash_flows"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Number of pages with reports
 | 
				
			||||||
 | 
							PageCount int64 `json:"page_count"`
 | 
				
			||||||
 | 
						} `json:"result"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Returns information about a created report by its identifier
 | 
				
			||||||
 | 
					func (c Reports) GetFinancial(params *GetFinancialReportParams) (*GetFinancialReportResponse, error) {
 | 
				
			||||||
 | 
						url := "/v1/finance/cash-flow-statement/list"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp := &GetFinancialReportResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						response, err := c.client.Request(http.MethodPost, url, params, resp)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						response.CopyCommonResponse(&resp.CommonResponse)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return resp, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,9 +89,7 @@ func TestGetReportDetails(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			http.StatusOK,
 | 
								http.StatusOK,
 | 
				
			||||||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
								map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
				
			||||||
			&GetReportDetailsParams{
 | 
								&GetReportDetailsParams{},
 | 
				
			||||||
				
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			`{
 | 
								`{
 | 
				
			||||||
				"result": {
 | 
									"result": {
 | 
				
			||||||
				  "code": "257bf213-ca57-405c-8edf-41d2ce22decf",
 | 
									  "code": "257bf213-ca57-405c-8edf-41d2ce22decf",
 | 
				
			||||||
@@ -129,3 +127,69 @@ func TestGetReportDetails(t *testing.T) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGetFinancial(t *testing.T) {
 | 
				
			||||||
 | 
						tests := []struct {
 | 
				
			||||||
 | 
							statusCode int
 | 
				
			||||||
 | 
							headers    map[string]string
 | 
				
			||||||
 | 
							params     *GetFinancialReportParams
 | 
				
			||||||
 | 
							response   string
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							// Test Ok
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								http.StatusOK,
 | 
				
			||||||
 | 
								map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
				
			||||||
 | 
								&GetFinancialReportParams{
 | 
				
			||||||
 | 
									Date: GetFinancialReportDatePeriod{
 | 
				
			||||||
 | 
										From: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2022-01-01T00:00:00.000Z"),
 | 
				
			||||||
 | 
										To:   core.TimeFromString(t, "2006-01-02T15:04:05Z", "2022-12-31T00:00:00.000Z"),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Page:     1,
 | 
				
			||||||
 | 
									PageSize: 1,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								`{
 | 
				
			||||||
 | 
									"result": {
 | 
				
			||||||
 | 
									  "cash_flows": [
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
										  "period": {
 | 
				
			||||||
 | 
											"id": 11567022278500,
 | 
				
			||||||
 | 
											"begin": "2022-08-01T00:00:00Z",
 | 
				
			||||||
 | 
											"end": "2022-08-15T00:00:00Z"
 | 
				
			||||||
 | 
										  },
 | 
				
			||||||
 | 
										  "orders_amount": 1000,
 | 
				
			||||||
 | 
										  "returns_amount": -3000,
 | 
				
			||||||
 | 
										  "commission_amount": 1437,
 | 
				
			||||||
 | 
										  "services_amount": 8471.28,
 | 
				
			||||||
 | 
										  "item_delivery_and_return_amount": 1991,
 | 
				
			||||||
 | 
										  "currency_code": "RUB"
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									  ],
 | 
				
			||||||
 | 
									  "page_count": 15
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}`,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							// Test No Client-Id or Api-Key
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								http.StatusUnauthorized,
 | 
				
			||||||
 | 
								map[string]string{},
 | 
				
			||||||
 | 
								&GetFinancialReportParams{},
 | 
				
			||||||
 | 
								`{
 | 
				
			||||||
 | 
									"code": 16,
 | 
				
			||||||
 | 
									"message": "Client-Id and Api-Key headers are required"
 | 
				
			||||||
 | 
								}`,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, test := range tests {
 | 
				
			||||||
 | 
							c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							resp, err := c.Reports().GetFinancial(test.params)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Error(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if resp.StatusCode != test.statusCode {
 | 
				
			||||||
 | 
								t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user