o
    Q?hg
                     @   s\   d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	 d dl
mZ dd Zg fdd	Zd
S )    )helpers)SERVER_TIMESTAMPdb)	getClientgetSupplierCredentials)getBlankProduct)saveLocationc              
   C   s  t | d}|d}t|d}|sdS |\}}|d}t|}tj|jj||d|d|dtd	}|d
i }	g }
|	rzU|	di }	|	rP|	dg ng }	|	D ]@}d}|di dg }i }|D ]}t	t|di di dd}|||d< ||7 }qf|

t|||dtd qTW n! ty } ztd| W Y d }~dS d }~ww t|||| dS t|d|
 dS )Nid
supplierId	inventoryFblankProductIdusernamepassword)	wsVersionr	   r   	productId)
target_cls	InventoryPartInventoryArrayPartInventoryr   InventoryLocationArrayInventoryLocationinventoryLocationQuantityQuantityvalueinventoryLocationIdpartId)r   totalQuantityr	   	updatedAtzUpdating Parts InventoryT)r   getr   r   r   serialize_objectservicegetInventoryLevelsdictintappendr   	ExceptionprintsaveInventory)paramsblankProductr
   Clientclientversionr	   credsInventoryResponser   inventoriesr   r   	locationsinventoryLocationslocationquantitye r5   R/var/www/html/riverr-enterprise-integrations-main/functions/Suppliers/Inventory.pyupdateBlankInventory	   s`   


$

r7   c                 C   sR   t d| d}|D ]}||dj|dd qtd|  t| | S )NblankProductsinventoryPricingsr	   T)mergezInventory Updated => )r   
collectiondocumentr   setr&   len)r   r/   refr   r5   r5   r6   r'   8   s
   r'   N)zeepr   configs.firebaser   r   functions.Suppliers.Authr   r   !functions.Suppliers.BlankProductsr   functions.Suppliers.Locationsr   r7   r'   r5   r5   r5   r6   <module>   s    /