lingxingapi 1.1.4__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.
Files changed (65) hide show
  1. lingxingapi/__init__.py +7 -0
  2. lingxingapi/ads/__init__.py +0 -0
  3. lingxingapi/ads/api.py +5946 -0
  4. lingxingapi/ads/param.py +192 -0
  5. lingxingapi/ads/route.py +134 -0
  6. lingxingapi/ads/schema.py +2615 -0
  7. lingxingapi/api.py +557 -0
  8. lingxingapi/base/__init__.py +0 -0
  9. lingxingapi/base/api.py +568 -0
  10. lingxingapi/base/param.py +59 -0
  11. lingxingapi/base/route.py +11 -0
  12. lingxingapi/base/schema.py +198 -0
  13. lingxingapi/basic/__init__.py +0 -0
  14. lingxingapi/basic/api.py +466 -0
  15. lingxingapi/basic/param.py +72 -0
  16. lingxingapi/basic/route.py +20 -0
  17. lingxingapi/basic/schema.py +218 -0
  18. lingxingapi/errors.py +152 -0
  19. lingxingapi/fba/__init__.py +0 -0
  20. lingxingapi/fba/api.py +1691 -0
  21. lingxingapi/fba/param.py +250 -0
  22. lingxingapi/fba/route.py +30 -0
  23. lingxingapi/fba/schema.py +987 -0
  24. lingxingapi/fields.py +50 -0
  25. lingxingapi/finance/__init__.py +0 -0
  26. lingxingapi/finance/api.py +3091 -0
  27. lingxingapi/finance/param.py +616 -0
  28. lingxingapi/finance/route.py +44 -0
  29. lingxingapi/finance/schema.py +1243 -0
  30. lingxingapi/product/__init__.py +0 -0
  31. lingxingapi/product/api.py +2643 -0
  32. lingxingapi/product/param.py +934 -0
  33. lingxingapi/product/route.py +49 -0
  34. lingxingapi/product/schema.py +1004 -0
  35. lingxingapi/purchase/__init__.py +0 -0
  36. lingxingapi/purchase/api.py +496 -0
  37. lingxingapi/purchase/param.py +126 -0
  38. lingxingapi/purchase/route.py +11 -0
  39. lingxingapi/purchase/schema.py +215 -0
  40. lingxingapi/sales/__init__.py +0 -0
  41. lingxingapi/sales/api.py +3200 -0
  42. lingxingapi/sales/param.py +723 -0
  43. lingxingapi/sales/route.py +70 -0
  44. lingxingapi/sales/schema.py +1718 -0
  45. lingxingapi/source/__init__.py +0 -0
  46. lingxingapi/source/api.py +1799 -0
  47. lingxingapi/source/param.py +176 -0
  48. lingxingapi/source/route.py +38 -0
  49. lingxingapi/source/schema.py +1011 -0
  50. lingxingapi/tools/__init__.py +0 -0
  51. lingxingapi/tools/api.py +291 -0
  52. lingxingapi/tools/param.py +73 -0
  53. lingxingapi/tools/route.py +8 -0
  54. lingxingapi/tools/schema.py +169 -0
  55. lingxingapi/utils.py +456 -0
  56. lingxingapi/warehourse/__init__.py +0 -0
  57. lingxingapi/warehourse/api.py +1778 -0
  58. lingxingapi/warehourse/param.py +506 -0
  59. lingxingapi/warehourse/route.py +28 -0
  60. lingxingapi/warehourse/schema.py +926 -0
  61. lingxingapi-1.1.4.dist-info/METADATA +73 -0
  62. lingxingapi-1.1.4.dist-info/RECORD +65 -0
  63. lingxingapi-1.1.4.dist-info/WHEEL +5 -0
  64. lingxingapi-1.1.4.dist-info/licenses/LICENSE +22 -0
  65. lingxingapi-1.1.4.dist-info/top_level.txt +1 -0
@@ -0,0 +1,616 @@
1
+ # -*- coding: utf-8 -*-
2
+ from typing import Any, Optional
3
+ from typing_extensions import Self
4
+ from pydantic import ValidationInfo, Field, field_validator, model_validator
5
+ from lingxingapi import utils
6
+ from lingxingapi.base.param import Parameter, PageOffestAndLength
7
+ from lingxingapi.fields import NonEmptyStr, NonNegativeInt, CurrencyCode
8
+
9
+
10
+ # 公共参数 ----------------------------------------------------------------------------------------------------------------------
11
+ class FinanceShare(PageOffestAndLength):
12
+ """财务数据共享参数"""
13
+
14
+ # 领星站点ID列表 (Seller.mid)
15
+ mids: Optional[list] = Field(None, alias="countryCodes")
16
+ # 领星店铺ID列表 (Seller.sid)
17
+ sids: Optional[list] = None
18
+
19
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20
+ @field_validator("mids", mode="before")
21
+ @classmethod
22
+ def _validate_mids(cls, v) -> list[int] | None:
23
+ if v is None:
24
+ return None
25
+ return utils.validate_array_of_unsigned_int(v, "站点ID mids")
26
+
27
+ @field_validator("sids", mode="before")
28
+ @classmethod
29
+ def _validate_sids(cls, v) -> list[int] | None:
30
+ if v is None:
31
+ return None
32
+ return utils.validate_array_of_unsigned_int(v, "店铺ID sids")
33
+
34
+
35
+ # 亚马逊交易数据 -----------------------------------------------------------------------------------------------------------------
36
+ # . Transactions
37
+ class Transactions(FinanceShare):
38
+ """查询亚马逊交易明细参数"""
39
+
40
+ # 交易开始日期 (本地时间), 双闭区间, 间隔不超过7天
41
+ transaction_start_date: Optional[str] = Field(None, alias="startDate")
42
+ # 交易结束日期 (本地时间), 双闭区间, 间隔不超过7天
43
+ transaction_end_date: Optional[str] = Field(None, alias="endDate")
44
+ # 数据更新开始时间 (中国时间), 间隔不超过7天
45
+ update_start_time: Optional[str] = Field(None, alias="gmtModifiedStart")
46
+ # 数据更新结束时间 (中国时间), 间隔不超过7天
47
+ update_end_time: Optional[str] = Field(None, alias="gmtModifiedEnd")
48
+ # 事件类型
49
+ event_types: Optional[str] = Field(None, alias="eventType")
50
+ # 交易类型
51
+ transaction_type: Optional[NonEmptyStr] = Field(None, alias="type")
52
+ # 搜索字段 ('transaction_id', 'transaction_number', 'amazon_order_id', 'settlement_id')
53
+ search_field: Optional[NonEmptyStr] = Field(None, alias="searchField")
54
+ # 搜索值
55
+ search_value: Optional[NonEmptyStr] = Field(None, alias="searchValue")
56
+
57
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58
+ @field_validator("transaction_start_date", "transaction_end_date", mode="before")
59
+ @classmethod
60
+ def _validate_date(cls, v, info: ValidationInfo) -> str | None:
61
+ if v is None:
62
+ return None
63
+ dt = utils.validate_datetime(v, False, "交易日期 %s" % info.field_name)
64
+ return "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
65
+
66
+ @field_validator("update_start_time", "update_end_time", mode="before")
67
+ @classmethod
68
+ def _validate_time(cls, v, info: ValidationInfo) -> str | None:
69
+ if v is None:
70
+ return None
71
+ dt = utils.validate_datetime(v, True, "数据更新时间 %s" % info.field_name)
72
+ # fmt: off
73
+ return "%04d-%02d-%02d %02d:%02d:%02d" % (
74
+ dt.year, dt.month, dt.day,
75
+ dt.hour, dt.minute, dt.second
76
+ )
77
+ # fmt: on
78
+
79
+ @field_validator("event_types", mode="before")
80
+ @classmethod
81
+ def _validate_event_types(cls, v) -> str | None:
82
+ if v is None:
83
+ return None
84
+ return ",".join(utils.validate_non_empty_str(v, "事件类型 event_types"))
85
+
86
+ @field_validator("search_field", mode="before")
87
+ @classmethod
88
+ def _validate_search_field(cls, v) -> str | None:
89
+ if v is None:
90
+ return None
91
+ if v == "transaction_id":
92
+ return "primary_id"
93
+ if v == "transaction_number":
94
+ return "id"
95
+ return v
96
+
97
+
98
+ # . Settlements
99
+ class Settlements(FinanceShare):
100
+ """查询亚马逊结算汇总参数"""
101
+
102
+ # 开始日期, 间隔不超过90天
103
+ start_date: str = Field(alias="startDate")
104
+ # 结束日期, 间隔不超过90天
105
+ end_date: str = Field(alias="endDate")
106
+ # 日期类型 (0: 结算开始时间, 1: 结算结束时间, 2: 转账时间)
107
+ date_type: NonNegativeInt = Field(alias="dateType")
108
+ # 搜索字段 ('settlement_id': 结算ID, 'settlement_number': 账单编号)
109
+ search_field: Optional[NonEmptyStr] = Field(None, alias="searchField")
110
+ # 搜索值
111
+ search_value: Optional[NonEmptyStr] = Field(None, alias="searchValue")
112
+ # 结算金额目标转换货币代码, 默认保持原币种
113
+ currency_code: Optional[CurrencyCode] = Field(None, alias="currencyCode")
114
+
115
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116
+ @field_validator("start_date", "end_date", mode="before")
117
+ @classmethod
118
+ def _validate_date(cls, v, info: ValidationInfo) -> str:
119
+ dt = utils.validate_datetime(v, False, "查询日期 %s" % info.field_name)
120
+ return "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
121
+
122
+ @field_validator("search_field", mode="before")
123
+ @classmethod
124
+ def _validate_search_field(cls, v) -> str | None:
125
+ if v is None:
126
+ return None
127
+ return "id" if v == "settlement_number" else v
128
+
129
+
130
+ # . Settlement Variances
131
+ class ShipmentSettlement(FinanceShare):
132
+ """查询亚马逊结算与发货差异参数"""
133
+
134
+ # 亚马逊卖家ID列表 (Seller.seller_id)
135
+ seller_ids: list = Field(alias="amazonSellerIds")
136
+ # 查询开始日期, 闭合区间
137
+ start_date: str = Field(alias="filterBeginDate")
138
+ # 查询结束日期, 闭合区间
139
+ end_date: str = Field(alias="filterEndDate")
140
+ # 日期类型 (01: 下单时间, 02: 付款时间, 03: 发货时间, 04: 结算时间, 05: 转账时间, 06: 更新时间)
141
+ date_type: NonEmptyStr = Field(alias="timeType")
142
+ # 亚马逊SKU列表
143
+ mskus: Optional[list] = None
144
+ # 领星本地SKU列表
145
+ lskus: Optional[list] = Field(None, alias="skus")
146
+ # 领星本地商品名称列表
147
+ product_names: Optional[list] = Field(None, alias="productNames")
148
+ # 亚马逊订单编码列表
149
+ amazon_order_ids: Optional[list] = Field(None, alias="orderNumbers")
150
+ # 配送编号列表
151
+ shipment_ids: Optional[list] = Field(None, alias="shipmentNumbers")
152
+ # 物流跟踪号列表
153
+ tracking_numbers: Optional[list] = Field(None, alias="trackCodes")
154
+ # 国家代码
155
+ country_codes: Optional[list] = Field(None, alias="countryCodes")
156
+
157
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158
+ @field_validator("seller_ids", mode="before")
159
+ @classmethod
160
+ def _validate_seller_ids(cls, v) -> list[str]:
161
+ return utils.validate_array_of_non_empty_str(v, "卖家ID seller_ids")
162
+
163
+ @field_validator("start_date", "end_date", mode="before")
164
+ @classmethod
165
+ def _validate_date(cls, v, info: ValidationInfo) -> str:
166
+ dt = utils.validate_datetime(v, False, "查询日期 %s" % info.field_name)
167
+ return "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
168
+
169
+ @field_validator("date_type", mode="before")
170
+ @classmethod
171
+ def _validate_date_type(cls, v) -> str:
172
+ if v == 1:
173
+ return "01"
174
+ if v == 2:
175
+ return "02"
176
+ if v == 3:
177
+ return "03"
178
+ if v == 4:
179
+ return "04"
180
+ if v == 5:
181
+ return "05"
182
+ if v == 6:
183
+ return "06"
184
+ return v
185
+
186
+ @field_validator(
187
+ "mskus",
188
+ "lskus",
189
+ "product_names",
190
+ "amazon_order_ids",
191
+ "shipment_ids",
192
+ "tracking_numbers",
193
+ "country_codes",
194
+ mode="before",
195
+ )
196
+ @classmethod
197
+ def _validate_list_of_str(cls, v, info: ValidationInfo) -> list[str] | None:
198
+ if v is None:
199
+ return None
200
+ return utils.validate_array_of_non_empty_str(v, "参数 %s" % info.field_name)
201
+
202
+
203
+ # . Receivables
204
+ class Receivables(FinanceShare):
205
+ """查询亚马逊应收账款参数"""
206
+
207
+ # 结算日期
208
+ settlement_date: str = Field(alias="settleMonth")
209
+ # 对账状态 (0: 未对账, 1: 已对账)
210
+ archive_status: Optional[NonNegativeInt] = Field(None, alias="archiveStatus")
211
+ # 应收状态 (0: 未收款, 1: 已收款)
212
+ received_state: Optional[NonNegativeInt] = Field(None, alias="receivedState")
213
+ # 排序字段 ('opening_balance': 期初余额, 'income': 收入, 'refund': 退款, 'spend' 支出, 'other': 其他)
214
+ sort_field: Optional[NonEmptyStr] = Field(None, alias="sortField")
215
+ # 排序方式 (0: 升序, 1: 降序)
216
+ sort_type: Optional[NonEmptyStr] = Field(None, alias="sortType")
217
+ # 结算金额目标转换货币代码, 默认保持原币种
218
+ currency_code: Optional[CurrencyCode] = Field(None, alias="currencyCode")
219
+
220
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
221
+ @field_validator("settlement_date", mode="before")
222
+ @classmethod
223
+ def _validate_settlement_date(cls, v) -> str:
224
+ dt = utils.validate_datetime(v, False, "结算日期 settlement_date")
225
+ return "%04d-%02d" % (dt.year, dt.month)
226
+
227
+ @field_validator("sort_field", mode="before")
228
+ @classmethod
229
+ def _validate_sort_field(cls, v) -> str | None:
230
+ if v is None:
231
+ return None
232
+ if v == "opening_balance":
233
+ return "beginningBalanceCurrencyAmount"
234
+ if v == "income":
235
+ return "incomeAmount"
236
+ if v == "refund":
237
+ return "refundAmount"
238
+ if v == "spend":
239
+ return "spendAmount"
240
+ return v
241
+
242
+ @field_validator("sort_type", mode="before")
243
+ @classmethod
244
+ def _validate_sort_type(cls, v) -> str | None:
245
+ if v is None:
246
+ return None
247
+ if v == 0:
248
+ return "asc"
249
+ if v == 1:
250
+ return "desc"
251
+ raise ValueError("排序方式 sort_type 必须为 0 (升序) 或 1 (降序)")
252
+
253
+
254
+ # 亚马逊库存数据 -----------------------------------------------------------------------------------------------------------------
255
+ # . Ledger Details
256
+ class LedgerDetail(PageOffestAndLength):
257
+ """查询亚马逊库存明细台账参数"""
258
+
259
+ # 亚马逊卖家ID列表 (Seller.seller_id)
260
+ seller_ids: list = Field(alias="sellerIds")
261
+ # 统计开始日期, 闭合区间
262
+ start_date: str = Field(alias="startDate")
263
+ # 统计结束日期, 闭合区间
264
+ end_date: str = Field(alias="endDate")
265
+ # 亚马逊ASIN列表
266
+ asins: Optional[list] = None
267
+ # 亚马逊SKU列表
268
+ mskus: Optional[list] = None
269
+ # 亚马逊FNSKU列表
270
+ fnskus: Optional[list] = None
271
+ # 国家代码 (库存位置)
272
+ country_codes: Optional[list] = Field(None, alias="locations")
273
+ # 事件类型
274
+ # (1: Shipments, 2 :CustomerReturns, 3 :WhseTransfers, 4 :Receipts, 5 :VendorReturns, 6 :Adjustments)
275
+ event_types: Optional[list] = Field(None, alias="eventTypes")
276
+ # 货物关联ID (支持模糊查询)
277
+ reference_id: Optional[NonNegativeInt] = Field(None, alias="referenceId")
278
+ # 库存处置结果 (1: SELLABLE, 2: UNSELLABLE, 3: ALL)
279
+ disposition: Optional[NonEmptyStr] = None
280
+
281
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
282
+ @field_validator("seller_ids", mode="before")
283
+ @classmethod
284
+ def _validate_seller_ids(cls, v) -> list[str]:
285
+ return utils.validate_array_of_non_empty_str(v, "卖家ID seller_ids")
286
+
287
+ @field_validator("start_date", "end_date", mode="before")
288
+ @classmethod
289
+ def _validate_date(cls, v, info: ValidationInfo) -> str:
290
+ dt = utils.validate_datetime(v, False, "查询日期 %s" % info.field_name)
291
+ return "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
292
+
293
+ @field_validator("asins", "mskus", "fnskus", "country_codes", mode="before")
294
+ @classmethod
295
+ def _validate_list_of_str(cls, v, info: ValidationInfo) -> list[str] | None:
296
+ if v is None:
297
+ return None
298
+ return utils.validate_array_of_non_empty_str(v, "参数 %s" % info.field_name)
299
+
300
+ @field_validator("event_types", mode="before")
301
+ @classmethod
302
+ def _validate_event_types(cls, v) -> list[int] | None:
303
+ if v is None:
304
+ return None
305
+ res: list = []
306
+ for i in utils.validate_array_of_non_empty_str(v, "事件类型 event_types"):
307
+ if i == "Shipments":
308
+ res.append("01")
309
+ elif i == "CustomerReturns":
310
+ res.append("02")
311
+ elif i == "WhseTransfers":
312
+ res.append("03")
313
+ elif i == "Receipts":
314
+ res.append("04")
315
+ elif i == "VendorReturns":
316
+ res.append("05")
317
+ elif i == "Adjustments":
318
+ res.append("06")
319
+ else:
320
+ res.append(i)
321
+ return res
322
+
323
+ @field_validator("disposition", mode="before")
324
+ @classmethod
325
+ def _validate_disposition(cls, v) -> str | None:
326
+ if v is None:
327
+ return None
328
+ if v == "SELLABLE":
329
+ return "01"
330
+ if v == "UNSELLABLE":
331
+ return "02"
332
+ if v == "ALL":
333
+ return "03"
334
+ return v
335
+
336
+
337
+ # . Ledger Summaries
338
+ class LedgerSummary(LedgerDetail):
339
+ """查询亚马逊库存汇总台账参数"""
340
+
341
+ # 查询维度 (1: 月, 2: 日)
342
+ query_dimension: NonNegativeInt = Field(alias="queryType")
343
+
344
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
345
+ @model_validator(mode="after")
346
+ def _date_adjustments(self) -> Self:
347
+ # 调整日期数据
348
+ if self.query_dimension == 1:
349
+ self.start_date = self.start_date[:7]
350
+ self.end_date = self.end_date[:7]
351
+ return self
352
+
353
+
354
+ # . Ledger Valuation
355
+ class LedgerValuation(PageOffestAndLength):
356
+ """查询亚马逊库存价值台账参数"""
357
+
358
+ # 开始日期, 不能跨月份
359
+ start_date: str
360
+ # 结束日期, 不能跨月份
361
+ end_date: str
362
+ # 日期类型
363
+ date_type: NonEmptyStr = Field(alias="query_type")
364
+ # 出入库类型列表
365
+ # 1 期初库存-FBA上月结存
366
+ # 10 调拨入库-FBA补货入库
367
+ # 11 调拨入库-FBA途损补回
368
+ # 12 调拨入库-FBA超签入库
369
+ # 13 调拨入库-FBA超签入库 (Close后)
370
+ # 14 调拨入库-FBA补货入库 (无发货单)
371
+ # 20 调拨入库-FBA调仓入库
372
+ # 35 调拨入库-FBA发货在途入库
373
+ # 25 盘点入库-FBA盘点入库
374
+ # 30 FBA退货-FBA无源单销售退货
375
+ # 31 FBA退货-FBA有源单销售退货
376
+ # 200 销售出库-FBA补发货销售
377
+ # 201 销售出库-FBA多渠道销售订单
378
+ # 202 销售出库-FBA亚马逊销售订单
379
+ # 205 其他出库-FBA补货出库
380
+ # 220 盘点出库-FBA盘点出库
381
+ # 15 调拨出库-FBA调仓出库
382
+ # 215 调拨出库-FBA移除
383
+ # 225 调拨出库-FBA发货在途出库
384
+ # 226 调拨出库-FBA发货途损
385
+ # 227 调拨出库-后补发货单在途出库
386
+ # 5 调整单- FBA对账差异入库调整
387
+ # 210 调整单-FBA对账差异出库调整
388
+ # 400 调整单-尾差调整
389
+ # 420 调整单-负库存数量调整
390
+ # 405 调整单-期初成本录入
391
+ transaction_types: Optional[list] = Field(None, alias="business_types")
392
+ # 出入库编码列表
393
+ transaction_numbers: Optional[list] = Field(None, alias="business_numbers")
394
+ # 源头单据号列表
395
+ source_numbers: Optional[list] = Field(None, alias="origin_accounts")
396
+ # 仓库名称列表
397
+ warehouse_names: Optional[list] = Field(None, alias="wh_names")
398
+ # 领星店铺名称列表
399
+ seller_names: Optional[list] = Field(None, alias="shop_names")
400
+ # 亚马逊SKU列表
401
+ mskus: Optional[list] = None
402
+ # 领星本地SKU列表
403
+ lskus: Optional[list] = Field(None, alias="skus")
404
+ # 库存处置结果列表 (1: 可用在途, 2: 可用, 3: 次品)
405
+ dispositions: Optional[list] = Field(None, alias="disposition_types")
406
+
407
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
408
+ @field_validator("transaction_types", mode="before")
409
+ @classmethod
410
+ def _validate_transaction_types(cls, v) -> list[int]:
411
+ if v is None:
412
+ return None
413
+ return utils.validate_array_of_unsigned_int(v, "出入库类型 transaction_types")
414
+
415
+ @field_validator("start_date", "end_date", mode="before")
416
+ @classmethod
417
+ def _validate_date(cls, v, info: ValidationInfo) -> str:
418
+ dt = utils.validate_datetime(v, False, "查询日期 %s" % info.field_name)
419
+ return "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
420
+
421
+ @field_validator("date_type", mode="before")
422
+ @classmethod
423
+ def _validate_date_type(cls, v) -> str | Any:
424
+ if v == 1:
425
+ return "01"
426
+ if v == 2:
427
+ return "02"
428
+ return v
429
+
430
+ @field_validator(
431
+ "transaction_numbers",
432
+ "source_numbers",
433
+ "warehouse_names",
434
+ "seller_names",
435
+ "mskus",
436
+ "lskus",
437
+ mode="before",
438
+ )
439
+ @classmethod
440
+ def _validate_list_of_str(cls, v, info: ValidationInfo) -> list[str] | None:
441
+ if v is None:
442
+ return None
443
+ return utils.validate_array_of_non_empty_str(v, "参数 %s" % info.field_name)
444
+
445
+ @field_validator("dispositions", mode="before")
446
+ @classmethod
447
+ def _validate_dispositions(cls, v) -> list[int] | None:
448
+ if v is None:
449
+ return None
450
+ return utils.validate_array_of_unsigned_int(v, "库存处置结果 dispositions")
451
+
452
+
453
+ # 亚马逊广告数据 -----------------------------------------------------------------------------------------------------------------
454
+ # . Ads Invoices
455
+ class AdsInvoices(FinanceShare):
456
+ """查询亚马逊广告发票参数"""
457
+
458
+ # 开始日期
459
+ start_date: str = Field(alias="invoice_start_time")
460
+ # 结束日期
461
+ end_date: str = Field(alias="invoice_end_time")
462
+ # 广告类型 ('SP', 'SB', 'SBV', 'SD')
463
+ ads_type: Optional[list[NonEmptyStr]] = None
464
+ # 领星站点ID列表 (Seller.mid)
465
+ mids: Optional[list] = None
466
+ # 搜索字段 ('invoice_id', 'msku', 'asin', 'campaign_name')
467
+ search_field: Optional[NonEmptyStr] = Field(None, alias="search_type")
468
+ # 搜索值
469
+ search_value: Optional[NonEmptyStr] = None
470
+
471
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
472
+ @field_validator("start_date", "end_date", mode="before")
473
+ @classmethod
474
+ def _validate_date(cls, v, info: ValidationInfo) -> str:
475
+ dt = utils.validate_datetime(v, True, "查询时间 %s" % info.field_name)
476
+ return "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
477
+
478
+ @field_validator("ads_type", mode="before")
479
+ @classmethod
480
+ def _validate_ads_type(cls, v) -> list[str] | None:
481
+ if v is None:
482
+ return None
483
+ if v in ("SP", "sp"):
484
+ return ["SPONSORED PRODUCTS"]
485
+ if v in ("SB", "sb"):
486
+ return ["SPONSORED BRANDS"]
487
+ if v in ("SBV", "sbv"):
488
+ return ["SPONSORED BRANDS VIDEO"]
489
+ if v in ("SD", "sd"):
490
+ return ["SPONSORED DISPLAY"]
491
+ if isinstance(v, list):
492
+ return v
493
+ return [v]
494
+
495
+ @field_validator("search_field", mode="before")
496
+ @classmethod
497
+ def _validate_search_field(cls, v) -> str | None:
498
+ if v is None:
499
+ return None
500
+ return "ads_campaign" if v == "campaign_name" else v
501
+
502
+
503
+ # . Ads Invoice Detail
504
+ class AdsInvoiceDetail(Parameter):
505
+ """查询亚马逊广告发票明细参数"""
506
+
507
+ # 领星店铺ID (Seller.sid)
508
+ sid: NonNegativeInt
509
+ # 广告发票ID
510
+ invoice_id: NonEmptyStr
511
+
512
+
513
+ # . Ads Campaign Invoices
514
+ class AdsCampaignInvoices(PageOffestAndLength):
515
+
516
+ # 领星店铺ID
517
+ sid: NonNegativeInt
518
+ # 广告发票ID
519
+ invoice_id: NonEmptyStr
520
+ # 广告类型 ('SP', 'SB', 'SBV', 'SD')
521
+ ads_type: Optional[list[NonEmptyStr]] = None
522
+ # 搜索字段 ('campaign_name', 'msku')
523
+ search_field: Optional[NonEmptyStr] = Field(None, alias="search_type")
524
+ # 搜索值
525
+ search_value: Optional[NonEmptyStr] = None
526
+
527
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
528
+ @field_validator("ads_type", mode="before")
529
+ @classmethod
530
+ def _validate_ads_type(cls, v) -> list[str] | None:
531
+ if v is None:
532
+ return None
533
+ if v in ("SP", "sp"):
534
+ return ["SPONSORED PRODUCTS"]
535
+ if v in ("SB", "sb"):
536
+ return ["SPONSORED BRANDS"]
537
+ if v in ("SBV", "sbv"):
538
+ return ["SPONSORED BRANDS VIDEO"]
539
+ if v in ("SD", "sd"):
540
+ return ["SPONSORED DISPLAY"]
541
+ if isinstance(v, list):
542
+ return v
543
+ return [v]
544
+
545
+ @field_validator("search_field", mode="before")
546
+ @classmethod
547
+ def _validate_search_field(cls, v) -> str | Any | None:
548
+ if v is None:
549
+ return None
550
+ return "ads_campaign" if v == "campaign_name" else v
551
+
552
+
553
+ # 亚马逊损益报告 -----------------------------------------------------------------------------------------------------------------
554
+ # . Income Statement Sellers
555
+ class IncomeStatementSellers(FinanceShare):
556
+ """查询损益报告-店铺维度参数"""
557
+
558
+ # 领星站点ID列表 (Seller.mid)
559
+ mids: Optional[list] = None
560
+ # 结算开始日期
561
+ start_date: str = Field(alias="startDate")
562
+ # 结算结束日期
563
+ end_date: str = Field(alias="endDate")
564
+ # 查询维度 (0: 日, 1: 月 | 默认 0)
565
+ query_dimension: Optional[NonNegativeInt] = Field(alias="monthlyQuery")
566
+ # 交易状态 ('Deferred', 'Disbursed', 'DisbursedAndPreSettled', 'All' | 默认 'Disbursed')
567
+ # Deferred: 订单未进入Transaction报告, 无法回款
568
+ # Disbursed: 订单已经进入Transaction报告, 可以回款
569
+ # DisbursedAndSettled: 可以回款和预结算订单
570
+ # All: 所有状态
571
+ transaction_status: Optional[NonEmptyStr] = Field(None, alias="orderStatus")
572
+ # 是否返回汇总数据 (0: 否, 1: 是 | 默认 0)
573
+ summarize: Optional[NonNegativeInt] = Field(None, alias="summaryEnabled")
574
+ # 结算金额目标转换货币代码, 默认保持原币种
575
+ currency_code: Optional[CurrencyCode] = Field(None, alias="currencyCode")
576
+
577
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
578
+ @field_validator("start_date", "end_date", mode="before")
579
+ @classmethod
580
+ def _validate_date(cls, v, info: ValidationInfo) -> str:
581
+ dt = utils.validate_datetime(v, False, "查询日期 %s" % info.field_name)
582
+ return "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
583
+
584
+ @field_validator("transaction_status", mode="before")
585
+ @classmethod
586
+ def _validate_transaction_status(cls, v) -> str | None:
587
+ if v is None:
588
+ return None
589
+ return "DisbursedAndPreSettled" if v == "DisbursedAndSettled" else v
590
+
591
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
592
+ @model_validator(mode="after")
593
+ def _date_adjustments(self) -> Self:
594
+ # 调整查询维度 & 日期数据
595
+ if self.query_dimension is not None and self.query_dimension == 1:
596
+ self.start_date = self.start_date[:7]
597
+ self.end_date = self.end_date[:7]
598
+ return self
599
+
600
+
601
+ # . Income Statement
602
+ class IncomeStatement(IncomeStatementSellers):
603
+ """查询损益报告-产品维度参数"""
604
+
605
+ # 搜索字段
606
+ search_field: Optional[NonEmptyStr] = Field(None, alias="searchField")
607
+ # 搜索值
608
+ search_value: Optional[list] = Field(None, alias="searchValue")
609
+
610
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
611
+ @field_validator("search_value", mode="before")
612
+ @classmethod
613
+ def _validate_search_value(cls, v) -> list[str] | None:
614
+ if v is None:
615
+ return None
616
+ return utils.validate_array_of_non_empty_str(v, "搜索值 search_value")
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # fmt: off
4
+ # 用户自定义费用管理 --------------------------------------------------------------------------------------------------------------
5
+ # https://apidoc.lingxing.com/#/docs/Finance/feeManagementType
6
+ USER_FEE_TYPES: str = "/bd/fee/management/open/feeManagement/otherFee/type"
7
+
8
+ # 亚马逊交易数据 -----------------------------------------------------------------------------------------------------------------
9
+ # https://apidoc.lingxing.com/#/docs/Finance/settlementTransactionList
10
+ TRANSACTIONS: str = "/bd/sp/api/open/settlement/transaction/detail/list"
11
+ # https://apidoc.lingxing.com/#/docs/Finance/settlementSummaryList
12
+ SETTLEMENTS: str = "/bd/sp/api/open/settlement/summary/list"
13
+ # https://apidoc.lingxing.com/#/docs/Finance/SettlementReport
14
+ SHIPMENT_SETTLEMENT: str = "/cost/center/api/settlement/report"
15
+ # https://apidoc.lingxing.com/#/docs/Finance/receivableReportList
16
+ RECEIVABLES: str = "/bd/sp/api/open/monthly/receivable/report/list"
17
+
18
+ # 亚马逊库存数据 -----------------------------------------------------------------------------------------------------------------
19
+ # https://apidoc.lingxing.com/#/docs/Finance/centerOdsDetailQuery
20
+ LEDGER_DETAIL: str = "/cost/center/ods/detail/query"
21
+ # https://apidoc.lingxing.com/#/docs/Finance/summaryQuery
22
+ LEDGER_SUMMARY: str = "/cost/center/ods/summary/query"
23
+ # https://apidoc.lingxing.com/#/docs/Finance/CostStream
24
+ LEDGER_VALUATION: str = "/cost/center/api/cost/stream"
25
+
26
+ # 亚马逊广告数据 -----------------------------------------------------------------------------------------------------------------
27
+ # https://apidoc.lingxing.com/#/docs/Finance/InvoiceList
28
+ ADS_INVOICES: str = "/bd/profit/report/open/report/ads/invoice/list"
29
+ # https://apidoc.lingxing.com/#/docs/Finance/InvoiceDetail
30
+ ADS_INVOICE_DETAIL: str = "/bd/profit/report/open/report/ads/invoice/detail"
31
+ # https://apidoc.lingxing.com/#/docs/Finance/InvoiceCampaignList
32
+ ADS_CAMPAIGN_INVOICES: str = "/bd/profit/report/open/report/ads/invoice/campaign/list"
33
+
34
+ # 亚马逊损益报告 -----------------------------------------------------------------------------------------------------------------
35
+ # https://apidoc.lingxing.com/#/docs/Finance/bdSeller
36
+ INCOME_STATEMENT_SELLERS: str = "/bd/profit/report/open/report/seller/list"
37
+ # https://apidoc.lingxing.com/#/docs/Finance/bdASIN
38
+ INCOME_STATEMENT_ASINS: str = "/bd/profit/report/open/report/asin/list"
39
+ # https://apidoc.lingxing.com/#/docs/Finance/bdParentASIN
40
+ INCOME_STATEMENT_PARENT_ASINS: str = "/bd/profit/report/open/report/parent/asin/list"
41
+ # https://apidoc.lingxing.com/#/docs/Finance/bdMSKU
42
+ INCOME_STATEMENT_MSKUS: str = "/bd/profit/report/open/report/msku/list"
43
+ # https://apidoc.lingxing.com/#/docs/Finance/bdSKU
44
+ INCOME_STATEMENT_LSKUS: str = "/bd/profit/report/open/report/sku/list"