producteca 2.0.15__py3-none-any.whl → 2.0.17__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- from typing import List, Optional
1
+ from typing import List, Optional, Union
2
2
  from pydantic import BaseModel, Field
3
3
  import logging
4
4
 
@@ -9,7 +9,7 @@ class SalesOrderProduct(BaseModel):
9
9
  id: int
10
10
  name: str
11
11
  code: str
12
- brand: str
12
+ brand: Optional[str] = None
13
13
 
14
14
 
15
15
  class SalesOrderVariationAttribute(BaseModel):
@@ -51,18 +51,18 @@ class SalesOrderPayment(BaseModel):
51
51
  coupon_amount: float = Field(alias="couponAmount")
52
52
  status: str
53
53
  method: str
54
- integration: SalesOrderPaymentIntegration
54
+ integration: Optional[SalesOrderPaymentIntegration] = None
55
55
  transaction_fee: float = Field(alias="transactionFee")
56
56
  installments: int
57
- card: SalesOrderCard
58
- notes: str
57
+ card: Optional[SalesOrderCard] = None
58
+ notes: Optional[str] = None
59
59
  has_cancelable_status: bool = Field(alias="hasCancelableStatus")
60
60
  id: int
61
61
 
62
62
 
63
63
  class SalesOrderIntegration(BaseModel):
64
- alternate_id: str = Field(alias="alternateId")
65
- integration_id: int = Field(alias="integrationId")
64
+ alternate_id: Optional[str] = Field(default=None, alias="alternateId")
65
+ integration_id: Union[str, int] = Field(alias="integrationId")
66
66
  app: int
67
67
 
68
68
 
@@ -73,13 +73,13 @@ class SalesOrderShipmentProduct(BaseModel):
73
73
 
74
74
 
75
75
  class SalesOrderShipmentMethod(BaseModel):
76
- tracking_number: str = Field(alias="trackingNumber")
76
+ tracking_number: Optional[str] = Field(alias="trackingNumber")
77
77
  tracking_url: str = Field(alias="trackingUrl")
78
78
  courier: str
79
- mode: str
79
+ mode: Optional[str] = None
80
80
  cost: float
81
81
  type: str
82
- eta: str
82
+ eta: Optional[Union[int, str]] = Field(None)
83
83
  status: str
84
84
 
85
85
 
@@ -94,12 +94,12 @@ class SalesOrderShipment(BaseModel):
94
94
  date: str
95
95
  products: List[SalesOrderShipmentProduct]
96
96
  method: SalesOrderShipmentMethod
97
- integration: SalesOrderShipmentIntegration
97
+ integration: Optional[SalesOrderShipmentIntegration] = None
98
98
 
99
99
 
100
100
  class SalesOrderResultItem(BaseModel):
101
101
  codes: List[str]
102
- contact_id: int = Field(alias="contactId")
102
+ contact_id: Optional[int] = Field(default=None, alias="contactId")
103
103
  currency: str
104
104
  date: str
105
105
  delivery_method: str = Field(alias="deliveryMethod")
@@ -107,33 +107,33 @@ class SalesOrderResultItem(BaseModel):
107
107
  id: str
108
108
  integration_ids: List[str] = Field(alias="integrationIds")
109
109
  integrations: List[SalesOrderIntegration]
110
- invoice_integration_app: int = Field(alias="invoiceIntegrationApp")
111
- invoice_integration_id: str = Field(alias="invoiceIntegrationId")
110
+ invoice_integration_app: Optional[int] = Field(default=None, alias="invoiceIntegrationApp")
111
+ invoice_integration_id: Optional[str] = Field(default=None, alias="invoiceIntegrationId")
112
112
  lines: List[SalesOrderLine]
113
113
  payments: List[SalesOrderPayment]
114
114
  payment_status: str = Field(alias="paymentStatus")
115
115
  payment_term: str = Field(alias="paymentTerm")
116
116
  product_names: List[str] = Field(alias="productNames")
117
- reserving_product_ids: str = Field(alias="reservingProductIds")
117
+ reserving_product_ids: Union[str, List[str]] = Field(alias="reservingProductIds")
118
118
  sales_channel: int = Field(alias="salesChannel")
119
119
  shipments: List[SalesOrderShipment]
120
- tracking_number: str = Field(alias="trackingNumber")
120
+ tracking_number: Optional[str] = Field(alias="trackingNumber")
121
121
  skus: List[str]
122
122
  status: str
123
123
  tags: List[str]
124
124
  warehouse: str
125
125
  company_id: int = Field(alias="companyId")
126
126
  shipping_cost: float = Field(alias="shippingCost")
127
- contact_phone: str = Field(alias="contactPhone")
127
+ contact_phone: Optional[str] = Field(default=None, alias="contactPhone")
128
128
  brands: List[str]
129
129
  courier: str
130
130
  order_id: int = Field(alias="orderId")
131
131
  updated_at: str = Field(alias="updatedAt")
132
- invoice_integration_created_at: str = Field(alias="invoiceIntegrationCreatedAt")
133
- invoice_integration_document_url: str = Field(alias="invoiceIntegrationDocumentUrl")
132
+ invoice_integration_created_at: Optional[str] = Field(default=None, alias="invoiceIntegrationCreatedAt")
133
+ invoice_integration_document_url: Optional[str] = Field(default=None, alias="invoiceIntegrationDocumentUrl")
134
134
  has_document_url: bool = Field(alias="hasDocumentUrl")
135
- integration_alternate_ids: str = Field(alias="integrationAlternateIds")
136
- cart_id: str = Field(alias="cartId")
135
+ integration_alternate_ids: Union[str, List[str]] = Field(alias="integrationAlternateIds")
136
+ cart_id: Optional[str] = Field(default=None, alias="cartId")
137
137
  amount: float
138
138
  has_any_shipments: bool = Field(alias="hasAnyShipments")
139
139
 
@@ -1,6 +1,6 @@
1
1
  import unittest
2
2
  from unittest.mock import patch, Mock
3
- from producteca.sales_orders.sales_orders import SaleOrder, SaleOrderInvoiceIntegration
3
+ from producteca.sales_orders.sales_orders import SaleOrder
4
4
  from producteca.client import ProductecaClient
5
5
 
6
6
 
@@ -12,7 +12,14 @@ class TestSaleOrder(unittest.TestCase):
12
12
  self.mock_response = {
13
13
  "id": self.sale_order_id,
14
14
  "contact": {"id": 1, "name": "Test Contact"},
15
- "lines": []
15
+ "lines": [],
16
+ "invoiceIntegration": {
17
+ 'id': 1,
18
+ 'integrationId': 'test-integration',
19
+ 'app': 1,
20
+ 'createdAt': '2023-01-01',
21
+ 'decreaseStock': True
22
+ }
16
23
  }
17
24
 
18
25
  @patch('requests.get')
@@ -34,7 +41,15 @@ class TestSaleOrder(unittest.TestCase):
34
41
  json=lambda: mock_labels
35
42
  )
36
43
 
37
- labels = self.client.SalesOrder(id=1234).get_shipping_labels()
44
+ labels = self.client.SalesOrder(id=1234, invoiceIntegration={
45
+ 'id': 1,
46
+ 'integrationId': 'test-integration',
47
+ 'app': 1,
48
+ 'createdAt': '2023-01-01',
49
+ 'decreaseStock': True,
50
+ "documentUrl": "https://aallala.copm",
51
+ "xmlUrl": "https://aallala.copm",
52
+ }).get_shipping_labels()
38
53
  self.assertEqual(labels, mock_labels)
39
54
  mock_get.assert_called_once()
40
55
 
@@ -44,7 +59,15 @@ class TestSaleOrder(unittest.TestCase):
44
59
  status_code=200
45
60
  )
46
61
 
47
- self.client.SalesOrder(id=1234).close()
62
+ self.client.SalesOrder(id=1234, invoiceIntegration={
63
+ 'id': 1,
64
+ 'integrationId': 'test-integration',
65
+ 'app': 1,
66
+ 'createdAt': '2023-01-01',
67
+ 'decreaseStock': True,
68
+ "documentUrl": "https://aallala.copm",
69
+ "xmlUrl": "https://aallala.copm",
70
+ }).close()
48
71
  mock_post.assert_called_once()
49
72
 
50
73
  @patch('requests.post')
@@ -54,7 +77,15 @@ class TestSaleOrder(unittest.TestCase):
54
77
  json=lambda: {"status": "cancelled"}
55
78
  )
56
79
 
57
- self.client.SalesOrder(id=1234).cancel()
80
+ self.client.SalesOrder(id=1234, invoiceIntegration={
81
+ 'id': 1,
82
+ 'integrationId': 'test-integration',
83
+ 'app': 1,
84
+ 'createdAt': '2023-01-01',
85
+ 'decreaseStock': True,
86
+ "documentUrl": "https://aallala.copm",
87
+ "xmlUrl": "https://aallala.copm",
88
+ }).cancel()
58
89
  mock_post.assert_called_once()
59
90
 
60
91
  @patch('requests.post')
@@ -65,31 +96,30 @@ class TestSaleOrder(unittest.TestCase):
65
96
  json=lambda: self.mock_response
66
97
  )
67
98
 
68
- response = self.client.SalesOrder.synchronize(sale_order)
99
+ response = self.client.SalesOrder(**sale_order.model_dump(by_alias=True)).synchronize()
69
100
  self.assertEqual(response.id, self.sale_order_id)
70
101
  mock_post.assert_called_once()
71
102
 
72
103
  @patch('requests.put')
73
104
  def test_invoice_integration(self, mock_put):
74
105
  invoice_data = {
75
- "id": 1,
76
- "integrationId": "test123",
77
- "app": 1
78
- }
79
- invoice_integration = SaleOrderInvoiceIntegration(**invoice_data)
80
- sale_order = SaleOrder(id=self.sale_order_id, invoiceIntegration=invoice_integration)
106
+ 'id': 1,
107
+ 'integrationId': 'test-integration',
108
+ 'app': 1,
109
+ 'createdAt': '2023-01-01',
110
+ 'decreaseStock': True,
111
+ "documentUrl": "https://aallala.copm",
112
+ "xmlUrl": "https://aallala.copm",
113
+ }
81
114
 
82
115
  mock_put.return_value = Mock(
83
116
  status_code=200,
84
- json=lambda: {
85
- "id": 1,
86
- "integrationId": "test123",
87
- "app": 1
88
- }
117
+ json=lambda: invoice_data,
118
+ ok=True
89
119
  )
90
120
 
91
- response = self.client.SalesOrder(**sale_order.model_dump()).invoice_integration()
92
- self.assertIsInstance(response, SaleOrder)
121
+ response = self.client.SalesOrder(id=self.sale_order_id, invoiceIntegration=invoice_data).invoice_integration()
122
+ self.assertTrue(response)
93
123
  mock_put.assert_called_once()
94
124
 
95
125
 
@@ -26,8 +26,7 @@ class TestSearchSalesOrder(unittest.TestCase):
26
26
  mock_get.return_value = mock_response
27
27
 
28
28
  response = self.client.SalesOrder.search(self.params)
29
-
30
- # Validate response
29
+
31
30
  self.assertEqual(response.count, 0)
32
31
  self.assertEqual(len(response.results), 1)
33
32
  self.assertEqual(response.results[0].id, "string")
@@ -35,14 +34,13 @@ class TestSearchSalesOrder(unittest.TestCase):
35
34
 
36
35
  @patch('requests.get')
37
36
  def test_search_saleorder_error(self, mock_get):
38
- # Mock error response
39
37
  mock_response = Mock()
40
38
  mock_response.json.return_value = {"error": "Invalid request"}
41
39
  mock_response.status_code = 400
42
40
  mock_get.return_value = mock_response
43
41
  with self.assertRaises(Exception):
44
42
  self.client.SalesOrder.search(self.params)
45
-
43
+
46
44
 
47
45
  if __name__ == '__main__':
48
46
  unittest.main()
@@ -14,14 +14,20 @@ class TestShipment(unittest.TestCase):
14
14
  products = [ShipmentProduct(product=1, variation=2, quantity=3)]
15
15
  method = ShipmentMethod(trackingNumber="TN123", trackingUrl="http://track.url", courier="DHL", mode="air", cost=10.5, type="express", eta=5, status="shipped")
16
16
  integration = ShipmentIntegration(id=1, integrationId="int123", app=10, status="active")
17
- payload = Shipment(date="2023-01-01", products=products, method=method, integration=integration)
17
+ payload = Shipment(date="2023-01-01", products=products, method=method, integration=integration).model_dump(by_alias=True)
18
18
 
19
19
  mock_response = MagicMock()
20
20
  mock_response.status_code = 201
21
- mock_response.json.return_value = {'success': True}
21
+ mock_response.json.return_value = payload
22
22
  mock_post.return_value = mock_response
23
23
  # Act
24
- shipment = self.client.SalesOrder(id=1234).add_shipment(payload)
24
+ shipment = self.client.SalesOrder(id=1234, invoiceIntegration={
25
+ 'id': 1,
26
+ 'integrationId': 'test-integration',
27
+ 'app': 1,
28
+ 'createdAt': '2023-01-01',
29
+ 'decreaseStock': True
30
+ }).add_shipment(payload)
25
31
 
26
32
  self.assertIsInstance(shipment, Shipment)
27
33
  mock_post.assert_called_once()
@@ -33,14 +39,20 @@ class TestShipment(unittest.TestCase):
33
39
  products = [ShipmentProduct(product=4, quantity=7)]
34
40
  method = ShipmentMethod(courier="FedEx", cost=15.0)
35
41
  integration = ShipmentIntegration(status="pending")
36
- payload = Shipment(date="2023-02-02", products=products, method=method, integration=integration)
42
+ payload = Shipment(date="2023-02-02", products=products, method=method, integration=integration).model_dump(by_alias=True)
37
43
 
38
44
  mock_response = MagicMock()
39
45
  mock_response.status_code = 200
40
- mock_response.json.return_value = {'updated': True}
46
+ mock_response.json.return_value = payload
41
47
  mock_put.return_value = mock_response
42
-
43
- shipment = self.client.SalesOrder(id=1234).update_shipment(shipment_id, payload)
48
+ # Act
49
+ shipment = self.client.SalesOrder(id=1234, invoiceIntegration={
50
+ 'id': 1,
51
+ 'integrationId': 'test-integration',
52
+ 'app': 1,
53
+ 'createdAt': '2023-01-01',
54
+ 'decreaseStock': True
55
+ }).update_shipment(shipment_id, payload)
44
56
 
45
57
  self.assertIsInstance(shipment, Shipment)
46
58
  mock_put.assert_called_once()