From e37cd4a1cce0d17aa81f890647c4fb1e52e40439 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Wed, 11 Feb 2026 07:26:48 +0100 Subject: [PATCH] 11.02.26 --- modules/automation/automation.py | 18 ++++++++++-------- modules/automation/cron.py | 1 + modules/purchase_trade/party.py | 12 ++++++++++++ modules/purchase_trade/stock.py | 12 ++++++++++++ .../purchase_trade/view/shipment_in_form.xml | 2 ++ .../purchase_trade/view/weight_report_form.xml | 4 +++- modules/purchase_trade/weight_report.py | 17 +++++++++++------ 7 files changed, 51 insertions(+), 15 deletions(-) diff --git a/modules/automation/automation.py b/modules/automation/automation.py index 3390b47..f30516e 100644 --- a/modules/automation/automation.py +++ b/modules/automation/automation.py @@ -236,20 +236,22 @@ class AutomationDocument(ModelSQL, ModelView, Workflow): doc.notes = (doc.notes or "") + f"Shipment found: {sh[0].number}\n" logger.info("BL_NUMBER:%s",sh[0].bl_number) if sh[0].incoming_moves: - weight_total = sum([m.lot.lot_quantity for m in sh[0].incoming_moves if m.lot.lot_type == 'physic']) - factor = weight_total / wr.net_landed_kg if wr.net_landed_kg else 1 + factor_net = wr.net_landed_kg / wr.bales if wr.bales else 1 + factor_gross = wr.gross_landed_kg / wr.bales if wr.bales else 1 for move in sh[0].incoming_moves: lot = move.lot if lot.lot_type == 'physic': wr_payload = { "chunk_key": lot.lot_chunk_key, - "gross_weight": float(round(lot.lot_gross_quantity / factor,5)), - "net_weight": float(round(lot.lot_quantity / factor,5)), - "tare_total": float(round(wr.tare_kg * (lot.lot_quantity / weight_total),5)) , + "gross_weight": float(round(lot.lot_qt * factor_gross,5)), + "net_weight": float(round(lot.lot_qt * factor_net,5)), + "tare_total": float(round(wr.tare_kg * (lot.lot_qt / wr.bales),5)) , "bags": int(lot.lot_qt), - "surveyor_code": 231, - "place_key": 0, - "report_date": 20260127 + "surveyor_code": sh[0].controller.get_alf(), + "place_key": sh[0].to_location.get_places(), + "report_date": wr.report_date, + "weight_date": wr.weight_date, + "agent": sh[0].agent.get_alf() } logger.info("PAYLOAD:%s",wr_payload) data = doc.create_weight_report(wr_payload) diff --git a/modules/automation/cron.py b/modules/automation/cron.py index ffeb303..78dbfd3 100644 --- a/modules/automation/cron.py +++ b/modules/automation/cron.py @@ -300,6 +300,7 @@ class AutomationCron(ModelSQL, ModelView): shipment.to_location = loc_to shipment.carrier = None #carrier shipment.supplier = agent + shipment.agent = agent shipment.vessel = vessel shipment.cargo_mode = 'bulk' shipment.bl_number = bl_number diff --git a/modules/purchase_trade/party.py b/modules/purchase_trade/party.py index f12f404..f24d28a 100755 --- a/modules/purchase_trade/party.py +++ b/modules/purchase_trade/party.py @@ -4,6 +4,7 @@ from trytond.exceptions import UserError from trytond.modules.purchase_trade.purchase import (TRIGGERS) from trytond.transaction import Transaction from decimal import getcontext, Decimal, ROUND_HALF_UP +from sql import Table class PartyExecution(ModelSQL,ModelView): "Party Execution" @@ -75,6 +76,17 @@ class Party(metaclass=PoolMeta): if sp: return round(((sp[0].cost / Decimal(100)) * Decimal(2.2046)),4) + def get_alf(self,name): + t = Table('alf') + cursor = Transaction().connection.cursor() + cursor.execute(*t.select( + t.ALF_CODE, + where=t.SHORT_NAME.ilike(f'%{name}%') + )) + rows = cursor.fetchall() + if rows: + return int(rows[0][0]) + @classmethod def getPartyByName(cls, party, category=None): party = party.upper() diff --git a/modules/purchase_trade/stock.py b/modules/purchase_trade/stock.py index 98e505b..862d3b7 100755 --- a/modules/purchase_trade/stock.py +++ b/modules/purchase_trade/stock.py @@ -32,6 +32,17 @@ logger = logging.getLogger(__name__) class Location(metaclass=PoolMeta): __name__ = 'stock.location' + def get_places(self,name): + t = Table('places') + cursor = Transaction().connection.cursor() + cursor.execute(*t.select( + t.PLACE_KEY, + where=t.PLACE_NAME.ilike(f'%{name}%') + )) + rows = cursor.fetchall() + if rows: + return int(rows[0][0]) + @classmethod def getLocationByName(cls, location, type): location = location.upper() @@ -436,6 +447,7 @@ class ShipmentIn(metaclass=PoolMeta): add_invoice = fields.Boolean("Add invoice") returned_id = fields.Char("Returned ID") result = fields.Char("Result",readonly=True) + agent = fields.Many2One('party.party',"Booking Agent") @classmethod def __setup__(cls): diff --git a/modules/purchase_trade/view/shipment_in_form.xml b/modules/purchase_trade/view/shipment_in_form.xml index 6116510..cf4837f 100755 --- a/modules/purchase_trade/view/shipment_in_form.xml +++ b/modules/purchase_trade/view/shipment_in_form.xml @@ -89,6 +89,8 @@ this repository contains the full copyright notices and license terms. -->