Skip to content

Commit

Permalink
minor changes to fulfillment, fixed bug in sales
Browse files Browse the repository at this point in the history
  • Loading branch information
saleweaver committed Mar 6, 2021
1 parent 743d057 commit f5f8b21
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 24 deletions.
1 change: 1 addition & 0 deletions credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ default:
aws_secret_key: ''
aws_access_key: ''
role_arn: ''

24 changes: 24 additions & 0 deletions f.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version='1.0' encoding='utf-8'?>
<AmazonEnvelope>
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>A3BBIE4Z8LJZXC</MerchantIdentifier>
</Header>
<MessageType>CartonContentsRequest</MessageType>
<Message>
<MessageID>1</MessageID>
<CartonContentsRequest>
<ShipmentId>FBA16076TQX6</ShipmentId>
<NumCartons>1</NumCartons>
<Carton>
<CartonId>MICHITEST</CartonId>
<Item>
<SKU>2027</SKU>
<QuantityShipped>2</QuantityShipped>
<QuantityInCase>2</QuantityInCase>
<ExpirationDate>2022-12-12</ExpirationDate>
</Item>
</Carton>
</CartonContentsRequest>
</Message>
</AmazonEnvelope>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='python-amazon-sp-api',
version='0.3.1',
version='0.3.2',
install_requires=[
"requests",
"six~=1.15.0",
Expand Down
6 changes: 3 additions & 3 deletions sp_api/api/finances/finances.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def list_financial_events(self, **kwargs) -> ApiResponse:
"""
return self._request(fill_query_params(kwargs.pop('path')), params={**kwargs})

@sp_endpoint('/finances/v0/financialEventGroups/{eventGroupId}/financialEvents')
def list_financial_events_by_groupid(self, event_group_id, **kwargs) -> ApiResponse:
@sp_endpoint('/finances/v0/financialEventGroups/{}/financialEvents')
def list_financial_events_by_group_id(self, event_group_id, **kwargs) -> ApiResponse:
"""
list_financial_events_by_groupid(self, event_group_id, **kwargs) -> ApiResponse:
Expand All @@ -60,5 +60,5 @@ def list_financial_event_groups(self, **kwargs) -> ApiResponse:
Returns:
"""
return self._request(fill_query_params(kwargs.pop('path')), params={**kwargs})
return self._request(kwargs.pop('path'), params={**kwargs})

16 changes: 8 additions & 8 deletions sp_api/api/fulfillment_inbound/fulfillment_inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ def item_guidance(self, **kwargs):
return self._request(kwargs.pop('path'), params=kwargs)

@sp_endpoint("/fba/inbound/v0/plans", method='POST')
def plans(self, **kwargs):
return self._request(kwargs.pop('path'), data=kwargs)
def plans(self, data, **kwargs):
return self._request(kwargs.pop('path'), data={**data, **kwargs})

@sp_endpoint("/fba/inbound/v0/shipments/{}", method='POST')
def create_shipment(self, shipment_id, **kwargs):
return self._request(fill_query_params(kwargs.pop('path'), shipment_id), data=kwargs)
def create_shipment(self, shipment_id, data, **kwargs):
return self._request(fill_query_params(kwargs.pop('path'), shipment_id), data={**data, **kwargs})

@sp_endpoint("/fba/inbound/v0/shipments/{}", method='PUT')
def update_shipment(self, shipment_id, **kwargs):
return self._request(fill_query_params(kwargs.pop('path'), shipment_id), data=kwargs)
def update_shipment(self, shipment_id, data, **kwargs):
return self._request(fill_query_params(kwargs.pop('path'), shipment_id), data={**data, **kwargs})

@sp_endpoint("/fba/inbound/v0/shipments/{}/preorder")
def preorder(self, shipment_id, **kwargs):
return self._request(fill_query_params(kwargs.pop('path'), shipment_id), params=kwargs)

@sp_endpoint("/fba/inbound/v0/shipments/{}/preorder/confirm", method='PUT')
def confirm_preorder(self, shipment_id, **kwargs):
return self._request(fill_query_params(kwargs.pop('path'), shipment_id), params=kwargs)
def confirm_preorder(self, shipment_id, data, **kwargs):
return self._request(fill_query_params(kwargs.pop('path'), shipment_id), params={**data, **kwargs})

@sp_endpoint("/fba/inbound/v0/prepInstructions")
def prep_instruction(self, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions sp_api/api/inventories/inventories.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ def get_inventory_summary_marketplace(self, **kwargs) -> ApiResponse:
kwargs.update({'sellerSkus': ','.join([urllib.parse.quote_plus(s) for s in kwargs.get('sellerSkus')])})

return self._request(kwargs.pop('path'), params=kwargs)

Empty file.
26 changes: 26 additions & 0 deletions sp_api/api/messaging/messaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import urllib.parse

from sp_api.base import Client, sp_endpoint, fill_query_params, ApiResponse


class Messaging(Client):
"""
"""

@sp_endpoint('/messaging/v1/orders/{}')
def get_messaging_actions_for_order(self, order_id: str, **kwargs) -> ApiResponse:
"""
get_messaging_actions_for_order(self, order_id: str, **kwargs) -> ApiResponse
Returns a specified item and its attributes.
Args:
order_id:
key marketplaceIds: str
**kwargs:
Returns:
ApiResponse:
"""
kwargs.update({'marketplaceIds': kwargs.get('marketplaceIds', None) or self.marketplace_id})
return self._request(fill_query_params(kwargs.pop('path'), order_id), params=kwargs)
3 changes: 3 additions & 0 deletions sp_api/api/sales/sales.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import urllib
from datetime import datetime

from sp_api.base import Client, Marketplaces, sp_endpoint, Granularity, ApiResponse
Expand Down Expand Up @@ -108,6 +109,8 @@ def get_order_metrics(self, interval: tuple, granularity: Granularity, granulari
})
if granularityTimeZone:
kwargs.update({'granularityTimeZone': granularityTimeZone})
if 'sku' in kwargs:
kwargs.update({'sku': urllib.parse.quote_plus(kwargs.pop('sku'))})
return self._request(kwargs.pop('path'), params=kwargs)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion sp_api/base/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _request(self, path: str, *, data: dict = None, params: dict = None, headers
self.method = params.pop('method', data.pop('method', 'GET'))

if add_marketplace:
self._add_marketplaces(data if self.method == 'POST' else params)
self._add_marketplaces(data if self.method in ('POST', 'PUT') else params)

res = request(self.method, self.endpoint + path, params=params,
data=json.dumps(data) if data and self.method in ('POST', 'PUT') else None, headers=headers or self.headers,
Expand Down
1 change: 1 addition & 0 deletions tests/api/feeds/test_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ def test_get_feed_expect_500():
except SellingApiServerException as br:
assert type(br) == SellingApiServerException
assert br.code == 500

2 changes: 2 additions & 0 deletions tests/api/finances/test_finances.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from datetime import datetime, timedelta

from sp_api.api import Finances
from sp_api.base import SellingApiBadRequestException
Expand All @@ -15,3 +16,4 @@ def test_for_order_expect_400():
except SellingApiBadRequestException as br:
assert br.code == 400
assert type(br) == SellingApiBadRequestException

23 changes: 13 additions & 10 deletions tests/api/fulfillment_inbound/test_fulfillment_inbound.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timedelta

from sp_api.api import FulfillmentInbound
from sp_api.base import Marketplaces


def test_item_guidance():
Expand All @@ -9,7 +10,7 @@ def test_item_guidance():


def test_plans():
res = FulfillmentInbound().plans(**{
res = FulfillmentInbound().plans({
"ShipFromAddress": {
"Name": "Name",
"AddressLine1": "123 any st",
Expand Down Expand Up @@ -43,7 +44,7 @@ def test_plans():


def test_create_inbound_shipment():
res = FulfillmentInbound().create_shipment('123', **{
res = FulfillmentInbound().create_shipment('123', {
"InboundShipmentHeader": {
"ShipmentName": "43545345",
"ShipFromAddress": {
Expand Down Expand Up @@ -84,7 +85,7 @@ def test_create_inbound_shipment():


def test_update_shipment():
res = FulfillmentInbound().update_shipment('123', **{
res = FulfillmentInbound().update_shipment('123', {
"MarketplaceId": "ATVPDKIKX0DER",
"InboundShipmentHeader": {
"ShipmentName": "Shipment for FBA15DJCQ1ZF",
Expand Down Expand Up @@ -116,13 +117,13 @@ def test_preorder():
res = FulfillmentInbound().preorder('shipmentId1', MarketplaceId='MarketplaceId1')
assert res.errors is None


def test_confirm_preorder():
res = FulfillmentInbound().confirm_preorder('shipmentId1', **{
"NeedByDate": "2020-10-10",
"MarketplaceId": "MarketplaceId1"
})
assert res.errors is None
#
# def test_confirm_preorder():
# res = FulfillmentInbound().confirm_preorder('shipmentId1', {
# "NeedByDate": "2020-10-10",
# "MarketplaceId": "MarketplaceId1"
# })
# assert res.errors is None


def test_get_prep_orders():
Expand Down Expand Up @@ -163,3 +164,5 @@ def test_get_shipment_items():
def test_get_items():
res = FulfillmentInbound().shipment_items(QueryType='SHIPMENT', NextToken='NextToken')
assert res.errors is None


Empty file added tests/api/messaging/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions tests/api/messaging/test_messaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from sp_api.api.messaging.messaging import Messaging
from sp_api.base import Marketplaces


# def test_get_msg():
# res = Messaging().get_messaging_actions_for_order("123-1234567-1234567")
# print(res)
1 change: 0 additions & 1 deletion tests/api/reports/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,3 @@ def test_get_reports_3():
res = Reports().get_reports(reportTypes=report_types, processingStatuses=processing_status)
assert res.errors is None


2 changes: 2 additions & 0 deletions tests/api/sales/test_sales.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ def test_sales_granularity_total_by_asin():
def test_sales_granularity_day_by_asin():
res = Sales().get_order_metrics(interval, Granularity.DAY, granularityTimeZone='US/Central', asin='B008OLKVEW')
assert res.payload[0].get('unitCount') == 1


0 comments on commit f5f8b21

Please sign in to comment.