NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

def extract_order_details(drupal_response):
order_info = []
line_items = drupal_response['entity']['params'][0]['line_items']

print("Extracting order details...") # Print statement added
print(f"Line items: {line_items}") # Print line items for inspection

for item in line_items:
order_info.append({
'sku': item['sku'],
'quantity': int(float(item['quantity'])),
'title': item['title'],
'total_price': item['total_price']
})
print(f"Extracted order info: {order_info}") # Print extracted order info
return order_info

def process_drupal_response(drupal_response):
print("Starting process_drupal_response...") # Start of function log
config = {
'engine': API_ENGINE,
'host': API_HOST,
'version': API_VERSION,
'token': API_KEY,
}
erp = acroERPFactory(config).create()

order_info = extract_order_details(drupal_response)

# Prepare AcroPart instances for the order items
print("Preparing line items for inventory check...") # Print statement added
line_items = [AcroPart(partnumber=item['sku'], quantity=item['quantity']) for item in order_info]
print(f"Line items prepared: {line_items}") # Print prepared line items

# Check inventory
inventory_errors = []
print("Checking inventory...") # Print statement added
try:
inventory_results = erp.check_for_inventory(line_items=line_items)
for result in inventory_results:
if result.error:
inventory_errors.append(f"Inventory error for {result.partnumber}: {result.error}")
print(f"Inventory check results: {inventory_results}") # Print inventory results
except Exception as e:
print(f"Error during inventory check: {e}")
# Get COGS
print("Getting COGS data...") # Print statement added
cogs_results = erp.get_cogs(line_items=line_items)
errors = []

# Debugging: print out the COGS results
print(f"COGS results: {cogs_results}")

for cogs_result in cogs_results:
print(f"COGS result: {cogs_result}") # Print individual COGS result for debugging
if cogs_result.error:
errors.append(cogs_result.error)
continue
# will need to correlate skus to order line items to get the account names
cogs_result.account_name_asset = "asset account name from order for sku"
cogs_result.account_name_cogs = "expense account name from order for sku (cogs account)"

if errors:
print("Errors in cogs results: ", errors)
return

print("Consuming inventory...") # Print statement added
consumption_errors = []
for item in line_items:
retry_count = 0
max_retries = 3
while retry_count < max_retries:
try:
error = erp.consume_inventory_unit(
item,
f"Huckleberry - consume inventory for order {drupal_response['entity']['source_entity_id'][0]['value']}",
apiOrigin="Huckleberry",
warehouseId="whl_0117H1CY78HMPE1AE335JQ7P0M"
# warehouseId="whl_01ECWJPCGR7D863EJC1T22MZ5F",
# inventory_location="Headquarters"
)
if error:
print(f"Error consuming inventory for {item.partnumber}: {error}")
consumption_errors.append(f"Error consuming inventory for {item.partnumber}: {error}")
break
except Exception as e:
print(f"Error consuming inventory for {item.partnumber}: {e}")
retry_count += 1
if retry_count < max_retries:
print(f"Retrying in 60 seconds... (Attempt {retry_count + 1}/{max_retries})")
time.sleep(60)
else:
consumption_errors.append(f"Failed to consume inventory for {item.partnumber} after {max_retries} attempts: {e}")
break
print(f"Consumption errors: {consumption_errors}") # Print consumption errors

return {
"inventory_errors": inventory_errors,
"cogs_errors": errors,
# "cogs_info": cogs_info,
"consumption_errors": consumption_errors,
}

take above function code for refrence and create a API in django ninja which will take sku items in list(single or multiple items) and hit the check inventrory, get cogs and cunsume inventory in a sequence only if 1st goes success then second goes sucess then third and return same error return by api in api response with logging. Please modify above function if required but functionality will be same.
from django ninja api which is getting created i need to get cogs information and use it for data shaping and then perform next action.
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.