@@ -1004,6 +1004,7 @@ def get_query(self):
10041004 code
10051005 }
10061006 ... on ManualDiscountApplication {
1007+ __typename
10071008 title
10081009 description
10091010 }
@@ -1020,6 +1021,14 @@ def get_query(self):
10201021 }
10211022 """
10221023
1024+ def is_discount_application (self , rec ):
1025+ if '__typename' in rec and rec ['__typename' ] in ['AutomaticDiscountApplication' ,
1026+ 'DiscountCodeApplication' ,
1027+ 'ManualDiscountApplication' ,
1028+ 'ScriptDiscountApplication' ]:
1029+ return True
1030+ return False
1031+
10231032 def update_bookmark (self , bookmark_value , bookmark_key = None , bulk_op_metadata = None ):
10241033 # Standard Singer bookmark
10251034 singer .write_bookmark (
@@ -1163,6 +1172,7 @@ def parse_bulk_jsonl(self, url):
11631172 resp = requests .get (url , stream = True , timeout = 60 )
11641173 current_order = None
11651174 current_line_items = []
1175+ current_discount_applications = []
11661176
11671177 for line in resp .iter_lines ():
11681178 if not line :
@@ -1173,18 +1183,25 @@ def parse_bulk_jsonl(self, url):
11731183 continue
11741184 # Detect line item (child) or order (parent)
11751185 if '__parentId' in rec :
1176- # It's a line item belonging to current_order
1177- current_line_items .append (rec )
1186+ if self .is_discount_application (rec ):
1187+ # It's a discount application belonging to current_order
1188+ current_discount_applications .append (rec )
1189+ else :
1190+ # It's a line item belonging to current_order
1191+ current_line_items .append (rec )
11781192 else :
11791193 if current_order :
11801194 current_order ["lineItems" ] = current_line_items
1195+ current_order ["discountApplications" ] = current_discount_applications
11811196 yield current_order
11821197 # Start tracking new parent group
11831198 current_order = rec
11841199 current_line_items = []
1200+ current_discount_applications = []
11851201 # Yield the last parent group (if exists)
11861202 if current_order :
11871203 current_order ["lineItems" ] = current_line_items
1204+ current_order ["discountApplications" ] = current_discount_applications
11881205 yield current_order
11891206
11901207 def transform_object (self , obj ):
@@ -1254,6 +1271,7 @@ def get_objects(self):
12541271 else :
12551272 LOGGER .info ("No data returned for the date range: %s to %s" ,
12561273 last_updated_at , query_end )
1274+ current_bookmark = max (current_bookmark , query_end )
12571275
12581276 self .clear_bulk_operation_state ()
12591277 last_updated_at = query_end
0 commit comments