Completed
Push — master ( e6b198...e30f90 )
by Messense
11:09 queued 10:06
created

MerchantOrder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 41.67%
Metric Value
dl 0
loc 44
ccs 5
cts 12
cp 0.4167
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get_by_filter() 0 13 2
A set_delivery() 0 10 1
A get() 0 9 2
A close() 0 5 1
1
# -*- coding: utf-8 -*-
2 10
from __future__ import absolute_import, unicode_literals
3 10
from optionaldict import optionaldict
4 10
from wechatpy.client.api.base import BaseWeChatAPI
5
6
7 10
class MerchantOrder(BaseWeChatAPI):
8
9 10
    def get(self, order_id):
10
        res = self._post(
11
            'merchant/order/getbyid',
12
            data={
13
                'order_id': order_id
14
            },
15
            result_processor=lambda x: x['order']
16
        )
17
        return res
18
19 10
    def get_by_filter(self, status=None, begin_time=None, end_time=None):
20
        filter_dict = optionaldict(
21
            status=status,
22
            begintime=begin_time,
23
            endtime=end_time
24
        )
25
26
        res = self._post(
27
            'merchant/order/getbyfilter',
28
            data=dict(filter_dict),
29
            result_processor=lambda x: x['order_list']
30
        )
31
        return res
32
33 10
    def set_delivery(self, order_id, company, track_no,
34
                     need_delivery=1, is_others=0):
35
        return self._post(
36
            'merchant/order/setdelivery',
37
            data={
38
                'order_id': order_id,
39
                'delivery_company': company,
40
                'delivery_track_no': track_no,
41
                'need_delivery': need_delivery,
42
                'is_others': is_others
43
            }
44
        )
45
46 10
    def close(self, order_id):
47
        return self._post(
48
            'merchant/order/close',
49
            data={
50
                'order_id': order_id
51
            }
52
        )
53