コード例 #1
0
def do_request_order_report(rep_type, start_date, end_date):
    
    for mws_acct in AmzMWSAccount.get_by_account_status():
        obj = AmzReportRequest.get_request(market_id=mws_acct.marketplace_id,
                                           name=mws_acct.name,
                                           rep_type=rep_type,
                                           start_date=start_date,
                                           end_date=end_date)

        if obj and not obj.is_done():
            log.warning('AmzReportRequest, <%s, %s, %s, %s, %s, %s>' % (
                mws_acct.marketplace_id, mws_acct.name,
                mws_acct.marketplace_id, rep_type, start_date, end_date))
            continue

        api = make_mws_api_by_account(mws_acct)
        try:
            req_resp = api.request_report(ReportType=rep_type,
                                          StartDate=start_date, 
                                          EndDate=end_date)
          
            AmzReportRequest(marketplace_id=mws_acct.marketplace_id,
                             name=mws_acct.name,
                             rep_type=rep_type,
                             request_id=req_resp.RequestReportResult
                                                .ReportRequestInfo
                                                .ReportRequestId,
                             report_id='',
                             start_date=start_date,
                             end_date=end_date,
                             ).add()
        except Exception:
            log.exception('')
            time.sleep(5)
コード例 #2
0
ファイル: erp_helper.py プロジェクト: QQiot/AMZ_EMAIL
def request_fba_inventory_report():
    #type returned [AmzReportRequest.FBA_INVENTORY, AmzReportRequest.RESERVED_SKU]
    #that is,['_GET_AFN_INVENTORY_DATA_', '_GET_RESERVED_INVENTORY_DATA_']
    rep_types = AmzFbaInvInfo.get_report_types()

    #get all infomation of amazon shops states,that is,marketplace_id name merchant_id key secret
    #get corresponding report thorough api of amz by offering given type(_GET_AFN_INVENTORY_DATA_、_GET_RESERVED_INVENTORY_DATA_)
    for mws_acct in AmzMWSAccount.get_by_account_status():
        # create api by offering information of shop state
        api = make_mws_api_by_account(mws_acct)
        for rep_type in rep_types:
            try:
                req_resp = api.request_report(ReportType=rep_type)
                #AmzReportRequest(base)
                AmzReportRequest(
                    marketplace_id=mws_acct.marketplace_id,
                    name=mws_acct.name,
                    rep_type=rep_type,
                    request_id=req_resp.RequestReportResult.ReportRequestInfo.
                    ReportRequestId,
                    report_id='',
                ).add()
                # just for test or check
                print(
                    'request_fba_inventory_report-------------------------------------------------------------------------------->'
                )
                print(
                    mws_acct.marketplace_id, mws_acct.name, rep_type, req_resp.
                    RequestReportResult.ReportRequestInfo.ReportRequestId)

            except Exception:
                log.exception('')
                time.sleep(5)
コード例 #3
0
def make_mws_api(market_id, name):
    from model import AmzMWSAccount

    account = AmzMWSAccount.get_by_market_name(market_id, name)
    if not account:
        return None

    return make_mws_api_by_account(account)
コード例 #4
0
ファイル: erp_helper.py プロジェクト: QQiot/AMZ_EMAIL
def fetch_shipment_data():
    def _list_ib_shipment_items(api, shipment_id):
        while True:
            try:
                return api.list_inbound_shipment_items(ShipmentId=shipment_id)
            except Exception as ex:
                for arg in ex.args:
                    if 'hrottled' in arg:
                        log.warning('get_report, RequestThrottled')
                        time.sleep(120)
                        continue
            raise ex

    def _save_available_shipments(shipment_list):
        for data in shipment_list:
            AmzShipmentInfo.save(
                market_id=mws_acct.marketplace_id,
                name=mws_acct.name,
                shipment_id=data.ShipmentId,
                shipment_name=data.ShipmentName,
                shipment_status=data.ShipmentStatus,
                label_prep_type=data.LabelPrepType,
                shipment_fc=data.DestinationFulfillmentCenterId,
                commit=False)
            #resp1 = _list_ib_shipment_items(api, ShipmentId=data.ShipmentId)
            resp1 = _list_ib_shipment_items(api, data.ShipmentId)
            items = resp1.ListInboundShipmentItemsResult.ItemData
            for item in items:
                AmzShipmentItem.save(market_id=mws_acct.marketplace_id,
                                     name=mws_acct.name,
                                     shipment_id=item.ShipmentId,
                                     sku=item.SellerSKU,
                                     fnsku=item.FulfillmentNetworkSKU,
                                     qty_in_case=item.QuantityInCase,
                                     qty_shipped=item.QuantityShipped,
                                     qty_received=item.QuantityReceived,
                                     commit=False)
            BaseMethod.commit()

    def _get_closed_shipments(market_id, name, shipment_list):
        avail_ids = [sm.ShipmentId for sm in shipment_list]
        shipment_list_db = AmzShipmentInfo.get_avail_shipment(market_id, name)
        return [
            sm.shipment_id for sm in shipment_list_db
            if sm.shipment_id not in avail_ids
        ]

    status_list = AmzShipmentInfo.get_shipment_avail_status()
    for mws_acct in AmzMWSAccount.get_by_account_status():
        api = make_mws_api_by_account(mws_acct)
        resp = api.list_inbound_shipments(ShipmentStatusList=status_list)
        shipment_list = resp.ListInboundShipmentsResult.ShipmentData
        _save_available_shipments(shipment_list)

        closed_ids = _get_closed_shipments(mws_acct.marketplace_id,
                                           mws_acct.name, shipment_list)
        if not closed_ids:
            continue
        resp = api.list_inbound_shipments(ShipmentIdList=closed_ids)
        shipment_list = resp.ListInboundShipmentsResult.ShipmentData
        _save_available_shipments(shipment_list)