27.01.26
This commit is contained in:
@@ -183,17 +183,7 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
|
||||
|
||||
doc.save()
|
||||
|
||||
def create_weight_report(self):
|
||||
wr_payload = {
|
||||
"chunk_key": 4660139,
|
||||
"gross_weight": 50000,
|
||||
"net_weight": 49500,
|
||||
"tare_total": 500,
|
||||
"bags": 100,
|
||||
"surveyor_code": 1424,
|
||||
"place_key": 100086,
|
||||
"report_date": 20260126
|
||||
}
|
||||
def create_weight_report(self,wr_payload):
|
||||
|
||||
response = requests.post(
|
||||
"http://automation-service:8006/weight-report",
|
||||
@@ -202,18 +192,7 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
|
||||
)
|
||||
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
# Exemple de data retournée :
|
||||
# {
|
||||
# "success": true,
|
||||
# "weight_report_key": 123456789
|
||||
# }
|
||||
|
||||
self.notes = (
|
||||
f"WR creation success: {data.get('success')}\n"
|
||||
f"WEIGHT_REPORT_KEY: {data.get('weight_report_key')}"
|
||||
)
|
||||
return response.json()
|
||||
|
||||
# -------------------------------------------------------
|
||||
# FULL PIPELINE
|
||||
@@ -223,8 +202,6 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
|
||||
def run_pipeline(cls, docs):
|
||||
for doc in docs:
|
||||
try:
|
||||
doc.create_weight_report()
|
||||
break
|
||||
logger.info("DATA_TYPE:%s",type(doc.metadata_json))
|
||||
metadata = json.loads(str(doc.metadata_json))
|
||||
logger.info("JSON STRUCTURE:%s",metadata)
|
||||
@@ -262,12 +239,14 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
|
||||
t.SELL_PREMIUM,
|
||||
t.SALE_CONTRACT_NUMBER,
|
||||
t.SALE_DECLARATION_KEY,
|
||||
t.SHIPMENT_CHUNK_KEY,
|
||||
where=(t.BOOKING_NUMBER == int(sh[0].reference))
|
||||
)
|
||||
cursor.execute(*query)
|
||||
rows = cursor.fetchall()
|
||||
logger.info("ROWS:%s",rows)
|
||||
if rows:
|
||||
sale_line = None
|
||||
for row in rows:
|
||||
logger.info("ROW:%s",row)
|
||||
#Purchase & Sale creation
|
||||
@@ -281,6 +260,8 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
|
||||
Sale = Pool().get('sale.sale')
|
||||
SaleLine = Pool().get('sale.line')
|
||||
dec_key = str(row[16]).strip()
|
||||
chunk_key = str(row[17]).strip()
|
||||
doc.notes = (doc.notes or "") + f"Lots found: {chunk_key}\n"
|
||||
lot_unit = str(row[5]).strip().lower()
|
||||
product = str(row[6]).strip().upper()
|
||||
lot_net_weight = Decimal(row[4])
|
||||
@@ -398,10 +379,27 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
|
||||
l.lot_quantity = round(lot_net_weight,2)
|
||||
l.lot_gross_quantity = round(lot_gross_weight,2)
|
||||
l.lot_premium = premium
|
||||
l.lot_chunk_key = int(chunk_key)
|
||||
logger.info("ADD_LOT:%s",l)
|
||||
LotQt.add_physical_lots(lqt,[l])
|
||||
|
||||
doc.create_weight_report()
|
||||
if sale_line:
|
||||
logger.info("CREATE_FINTRADE_WR_FOR_SL:%s",sale_line)
|
||||
weight_total = sum([l.lot_quantity for l in sale_line.lots if l.lot_type == 'physic'])
|
||||
factor = weight_total / wr.net_landed_kg if wr.net_landed_kg else 1
|
||||
for lot in sale_line.lots:
|
||||
wr_payload = {
|
||||
"chunk_key": lot.lot_chunk_key,
|
||||
"gross_weight": round(lot.lot_gross_quantity / factor,5),
|
||||
"net_weight": round(lot.lot_quantity / factor,5),
|
||||
"tare_total": round(wr.tare_kg * (lot.lot_quantity / weight_total),5) ,
|
||||
"bags": int(wr.bales * (lot.lot_quantity / weight_total)),
|
||||
"surveyor_code": 231,
|
||||
"place_key": 0,
|
||||
"report_date": 20260127
|
||||
}
|
||||
data = doc.create_weight_report(wr_payload)
|
||||
doc.notes = (doc.notes or "") + f"WR created in Fintrade: {data.get('success')}\n"
|
||||
doc.notes = (doc.notes or "") + f"WR key: {data.get('weight_report_key')}\n"
|
||||
|
||||
# if cls.rule_set.ocr_required:[]
|
||||
# cls.run_ocr([doc])
|
||||
|
||||
@@ -59,6 +59,7 @@ class Lot(metaclass=PoolMeta):
|
||||
delta_pr = fields.Numeric("Delta Pr")
|
||||
delta_amt = fields.Numeric("Delta Amt")
|
||||
warrant_nb = fields.Char("Warrant Nb")
|
||||
lot_chunk_key = fields.Integer("Chunk key")
|
||||
#fees = fields.Many2Many('fee.lots', 'lot', 'fee',"Fees")
|
||||
dashboard = fields.Many2One('purchase.dashboard',"Dashboard")
|
||||
pivot = fields.Function(
|
||||
@@ -1096,6 +1097,7 @@ class LotQt(
|
||||
newlot.lot_shipment_internal = self.lot_shipment_internal
|
||||
newlot.lot_shipment_out = self.lot_shipment_out
|
||||
newlot.lot_product = self.lot_p.line.product
|
||||
newlot.lot_chunk_key = l.lot_chunk_key
|
||||
if self.lot_s:
|
||||
newlot.sale_line = self.lot_s.sale_line if self.lot_s.sale_line else None
|
||||
newlot.lot_type = 'physic'
|
||||
@@ -2456,6 +2458,7 @@ class LotAddLine(ModelView):
|
||||
lot_gross_quantity = fields.Numeric("Gross weight")
|
||||
lot_unit_line = fields.Many2One('product.uom', "Unit",required=True)
|
||||
lot_premium = fields.Numeric("Premium")
|
||||
lot_chunk_key = fields.Integer("Chunk key")
|
||||
|
||||
# @fields.depends('lot_qt')
|
||||
# def on_change_with_lot_quantity(self):
|
||||
|
||||
Reference in New Issue
Block a user