Пример #1
0
def process_waiting_shipments():
    from .kitchensink.extensions import fulfil

    Shipment = fulfil.model('stock.shipment.out')
    shipments = list(
        Shipment.search_read_all([('state', '=', 'waiting')],
                                 [('sale_date', 'ASC'), ('priority', 'ASC')],
                                 ['sale_date', 'priority']))
    results = []
    for shipment in shipments:
        print(shipment)
        count = 5  # Initial count
        while count:
            if count < 5:
                print("Retrying")
            try:
                results.append(Shipment.assign_try([shipment['id']]))
            except fulfil_client.client.ServerError:
                count -= 1  # Decrement the count, try again
            else:
                break
        else:
            print("Yuck! This one is pretty bad", shipment)

    requests.post(os.environ['SLACK_WEBHOOK_URL'],
                  json={
                      'text':
                      'Tried to assign Shipments',
                      'attachments': [{
                          'title':
                          'Assigning Shipments',
                          'thumb_url':
                          'http://example.com/path/to/thumb.png',
                          'fields': [{
                              'title': 'Attempted',
                              'value': str(len(shipments)),
                          }, {
                              'title':
                              'Assigned',
                              'value':
                              str(len([r for r in results if r])),
                              'short':
                              True,
                          }, {
                              'title':
                              'Still Waiting',
                              'value':
                              str(len([r for r in results if not r])),
                              'short':
                              True,
                          }]
                      }]
                  })
Пример #2
0
def reassign_all_shipments():
    from kitchensink.extensions import fulfil

    Shipment = fulfil.model('stock.shipment.out')

    shipments = list(
        Shipment.search_read_all([('state', 'in', ('waiting', 'assigned'))],
                                 None, None))
    for shipment in shipments:
        print "Making shimpent %s wait" % shipment['id']
        Shipment.wait([shipment['id']])
    process_waiting_shipments()
Пример #3
0
def process_waiting_shipments():
    from kitchensink.extensions import fulfil

    Shipment = fulfil.model('stock.shipment.out')
    shipments = list(
        Shipment.search_read_all(
            [('state', '=', 'waiting')],
            [('sale_date', 'ASC'), ('priority', 'ASC')],
            ['sale_date', 'priority']
        )
    )
    results = []
    for shipment in shipments:
        print shipment
        count = 5   # Initial count
        while count:
            if count < 5:
                print "Retrying"
            try:
                results.append(
                    Shipment.assign_try([shipment['id']])
                )
            except fulfil_client.client.ServerError:
                count -= 1  # Decrement the count, try again
            else:
                break
        else:
            print "Yuck! This one is pretty bad", shipment

    requests.post(
        os.environ['SLACK_WEBHOOK_URL'],
        json={
            'text': 'Tried to assign Mejuri Shipments',
            'attachments': [{
                'title': 'Assigning Shipments',
                'thumb_url': 'https://dto508s2j2p46.cloudfront.net/assets/mejuri_label-86c1982b0d84c5017186e435ff666485.png',
                'fields': [{
                    'title': 'Attempted',
                    'value': str(len(shipments)),
                }, {
                    'title': 'Assigned',
                    'value': str(len(filter(lambda r: r, results))),
                    'short': True,
                }, {
                    'title': 'Still Waiting',
                    'value': str(len(filter(lambda r: not r, results))),
                    'short': True,
                }]
            }]
        }
    )
Пример #4
0
def get_stats():
    from kitchensink.extensions import fulfil
    Shipment = fulfil.model('stock.shipment.out')
    warehouse_id = 18
    domain = [
        ('warehouse', '=', warehouse_id),
        ('state', '=', 'assigned'),
        # ('state', '=', 'waiting'),
        ('shipping_batch', '=', None),
        # ('planned_date', '=', '2019-09-12'),
        ('carrier', '!=', None),
    ]
    unbatched_shipment_count = Shipment.search_count(domain)
    print("Unbatched: {}".format(unbatched_shipment_count))
    domain.append(('priority', 'in', ['0', '1']))
    priority_count = Shipment.search_count(domain)
    print("of which {} are high priority".format(priority_count))