コード例 #1
0
def test_build_date_range(sample_date_range_input: list,
                          expected_date_range: list) -> None:
    result = []
    for sample in sample_date_range_input:
        result.append(build_date_range(start=sample['start'],
                                       end=sample['end']))

    assert expected_date_range == result
コード例 #2
0
    def plenty_api_get_orders_by_date(self, start, end, date_type='create',
                                      additional=None, refine=None):
        """
            Get all orders within a specific date range.

            Parameter:
                start [str]         -   Start date
                end   [str]         -   End date
                date_type [str]     -   Specify the type of date
                                        {Creation, Change, Payment, Delivery}
                additional [list]   -   Additional arguments for the query
                                        as specified in the manual
                refine [dict]       -   Apply filters to the request
                                        Example:
                                        {'orderType': '1,4', referrerId: '1'}
                                        Restrict the request to order types:
                                            1 and 4 (sales orders and refund)
                                        And restrict it to only orders from
                                        the referrer with id '1'

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """

        date_range = utils.build_date_range(start=start, end=end)
        if not date_range:
            print(f"ERROR: Invalid range {start} -> {end}")

        if not utils.check_date_range(date_range=date_range):
            print(f"ERROR: {date_range['start']} -> {date_range['end']}")
            return {}

        query = utils.build_query_date(date_range=date_range,
                                       date_type=date_type)
        if refine:
            invalid_keys = set(refine.keys()).difference(
                utils.VALID_ORDER_REFINE_KEYS)
            if invalid_keys:
                print(f"Invalid refine argument key removed: {invalid_keys}")
                for invalid_key in invalid_keys:
                    refine.pop(invalid_key, None)
            query.update(refine)

        if additional:
            query.update({'with': additional})

        orders = self.__repeat_get_request_for_all_records(domain='orders',
                                                           query=query)
        if not orders:
            return {}

        if self.data_format == 'json':
            return orders

        if self.data_format == 'dataframe':
            return utils.json_to_dataframe(json=orders)
コード例 #3
0
    def plenty_api_get_orders_by_date(self,
                                      start,
                                      end,
                                      date_type='create',
                                      additional=None,
                                      refine=None):
        """
            Get all orders within a specific date range.

            Parameter:
                start       [str]   -   Start date
                end         [str]   -   End date
                date_type   [str]   -   Specify the type of date
                                        {Creation, Change, Payment, Delivery}
                additional  [list]  -   Additional arguments for the query
                                        as specified in the manual
                refine      [dict]  -   Apply filters to the request
                                        Example:
                                        {'orderType': '1,4', referrerId: '1'}
                                        Restrict the request to order types:
                                            1 and 4 (sales orders and refund)
                                        And restrict it to only orders from
                                        the referrer with id '1'

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """

        date_range = utils.build_date_range(start=start, end=end)
        if not date_range:
            print(f"ERROR: Invalid range {start} -> {end}")

        if not utils.check_date_range(date_range=date_range):
            print(f"ERROR: {date_range['start']} -> {date_range['end']}")
            return {}

        query = utils.build_query_date(date_range=date_range,
                                       date_type=date_type)

        query = utils.sanity_check_parameter(domain='order',
                                             query=query,
                                             refine=refine,
                                             additional=additional)

        orders = self.__repeat_get_request_for_all_records(domain='orders',
                                                           query=query)

        orders = utils.transform_data_type(data=orders,
                                           data_format=self.data_format)

        return orders