This commit is contained in:
2026-02-03 12:19:44 +01:00
parent 0a41765551
commit f4a53f2705
2 changed files with 53 additions and 22 deletions

View File

@@ -308,9 +308,9 @@ class AutomationCron(ModelSQL, ModelView):
# Sauvegarder ce shipment uniquement
ShipmentIn.save([shipment])
shipment._create_lots_from_fintrade()
inv_date,inv_nb = shipment._create_lots_from_fintrade()
shipment.controller = shipment.get_controller()
shipment.instructions = shipment.get_instructions_html()
shipment.instructions = shipment.get_instructions_html(inv_date,inv_nb)
ShipmentIn.save([shipment])
trans_shipment.commit()
successful_shipments += 1

View File

@@ -466,23 +466,41 @@ class ShipmentIn(metaclass=PoolMeta):
if c.party.IsAvailableForControl(self):
return c.party
def get_instructions_html(self):
def get_instructions_html(self,inv_date,inv_nb):
vessel = self.vessel.vessel_name if self.vessel else ""
lines = [
"<p>Hi,</p>",
"<p>Please find details below for the requested control</p>",
f"<p><strong>BL number:</strong> {self.bl_number}</p>",
f"<p><strong>ETA:</strong> {self.eta}</p>",
f"<p><strong>Vessel:</strong> {vessel}</p>",
]
if self.incoming_moves:
for m in self.incoming_moves:
if m.lot:
lines.append(
"<p>"
f"<strong>Lot nb:</strong> {m.lot.lot_name} | "
f"<strong>Net Qt:</strong> {m.lot.get_current_quantity()} {m.lot.lot_unit_line.symbol} | "
f"<strong>Gross Qt:</strong> {m.lot.get_current_gross_quantity()} {m.lot.lot_unit_line.symbol}"
"</p>"
)
tot_net = sum([m.lot.get_current_quantity() for m in self.incoming_moves])
tot_gross = sum([m.lot.get_current_gross_quantity() for m in self.incoming_moves])
tot_bale = sum([m.lot.lot_qt for m in self.incoming_moves])
customer = self.incoming_moves[0].lot.sale_line.sale.party.name if self.incoming_moves[0].lot.sale_line else ""
unit = self.incoming_moves[0].lot.lot_unit_line.symbol
lines.append("<p>"
f"<strong>Customer:</strong> {customer}"
"</p>"
)
lines.append("<p>"
f"<strong>Invoice Nb:</strong> {inv_nb}"
"</p>"
)
lines.append("<p>"
f"<strong>Invoice Date:</strong> {inv_date}"
"</p>"
)
lines.append(
"<p>"
f"<strong>Nb Bales:</strong> {tot_bale} | "
f"<strong>Net Qt:</strong> {tot_net} {unit} | "
f"<strong>Gross Qt:</strong> {tot_gross} {unit}"
"</p>"
)
return "".join(lines)
@@ -533,6 +551,8 @@ class ShipmentIn(metaclass=PoolMeta):
cursor.execute(*query)
rows = cursor.fetchall()
logger.info("ROWS:%s",rows)
inv_date = None
inv_nb = None
if rows:
sale_line = None
for row in rows:
@@ -559,6 +579,8 @@ class ShipmentIn(metaclass=PoolMeta):
customer = str(row[7]).strip().upper()
sell_price_currency = str(row[8]).strip().upper()
sell_price_unit = str(row[9]).strip().lower()
inv_date = str(row[13]).strip()
inv_nb = str(row[11]).strip()
sell_price = Decimal(row[10])
premium = Decimal(row[14])
reference = Decimal(row[15])
@@ -674,7 +696,7 @@ class ShipmentIn(metaclass=PoolMeta):
logger.info("ADD_LOT:%s",int(chunk_key))
LotQt.add_physical_lots(lqt,[l])
return sale_line
return inv_date,inv_nb
def html_to_text(self,html_content):
text = re.sub(r"<br\s*/?>", "\n", html_content, flags=re.IGNORECASE)
@@ -686,25 +708,34 @@ class ShipmentIn(metaclass=PoolMeta):
@ModelView.button
def send(cls, shipments):
Date = Pool().get('ir.date')
Attachment = Pool().get('ir.attachment')
for sh in shipments:
sh.result = "Email not sent"
attachment = None
if sh.add_bl:
attachments = Attachment.search([
('res_model', '=', 'stock.shipment.in'),
('res_id', '=', sh.id),
])
if attachments:
attachment = attachments[0]
if sh.controller:
Contact = Pool().get('party.contact_mechanism')
contact = Contact.search(['party','=',sh.controller.id])
if contact:
# f = open("/tmp/instruction.pdf", "rb")
# encoded = base64.b64encode(f.read()).decode()
payload = {
"to": [contact[0].value],
"subject": "Request for control",
"body": sh.html_to_text(sh.instructions),
# "attachments": [
# {
# "filename": "instruction.pdf",
# "content": encoded,
# "content_type": "application/pdf"
# }
# ],
"attachments": [
{
"filename": attachment.name,
"content": attachment.data,
"content_type": "application/pdf"
}
],
"meta": {
"shipment": sh.bl_number,
"controller": sh.controller.id