
    MRjD                     (    d Z d Zedk(  r e        yy)aa  Populate the Full snapshot and calculate its unit costs.

Run on the VPS from the project virtualenv:
    python3 -m app.scripts.backfill_full_stock

Apply app/scripts/sql/full_tables.sql first (and optionally
full_tariffs_seed.sql). This script never creates or migrates database schema;
the project requires all schema changes to be applied manually.
c                     dd l } ddlm} ddlm}m} ddlm} | j                         }|j                  ddd       |j                         } |       } ||	      }	 |j                  |      j                  |j                  d
k(        j                         }	|	dk(  rt        d       t        d       |j!                  |j"                        }
|
d   }|
d   }t        d|d    d|d    d|j%                  dd       d       t        d|j%                  dd       d|j%                  dd              ddlm} |j                  |j                  |j*                              j-                         xs d}|j                  |j/                  |j0                              j-                         xs d}|j                  |j/                  |j2                              j-                         xs d}t        d| d| d| d        |j=                          y # t4        $ r' dd l}|j9                          |j;                          Y @w xY w# |j=                          w xY w)!N    )SessionLocal)FullInventoryFullStorageTariff)FullServicez--include-ageing
store_truezBQuery the rate-limited Full operations history for real stock age.)actionhelp)dbTz3WARNING: no active tariffs in full_storage_tariffs.zFStock can be synchronized, but Full costs require configured tariffs.
)include_ageingstockcostzSync: ads_fullz Full ads, inventoriesz inventory records, dimensions_updatedz  real dimension records updated.zFull cost written for updatedz SKUs. reason )funczfull_inventory: z rows | available z | in transit .)argparseapp.core.databaser   app.models.fullr   r   app.services.full_servicer   ArgumentParseradd_argument
parse_argsqueryfilteractivecountprintsync_and_costr   get
sqlalchemyr   idscalarsumavailable_qtyin_transit_qty	Exception	traceback	print_excrollbackclose)r   r   r   r   r   parserargsr   svc	n_tariffsresultr   r   r   total	available
in_transitr,   s                     M/var/www/hypershopcomercio.com.br/hyper-ai/app/scripts/backfill_full_stock.pymainr9      s&   .@5$$&F
*<a  cD	B

CHH./667H7O7OSW7WX^^`	>GH[\""$2E2E"Fwf~uZ()U=5I4JJ^/344TV 	W&txx	1'=&>gdhhxY[F\E]^_#M$4$456==?D1HHTXXm&A&ABCJJLQPQ	XXdhh}'C'CDELLNSRS
 '9)NS]R^^_`a 	
  

 	
s%   F'H -II	 II	 	I__main__N)__doc__r9   __name__     r8   <module>r?      s$   $N zF r>   