This commit is contained in:
2026-02-02 17:27:14 +01:00
parent 7f7b103945
commit a4f0a08469
3 changed files with 43 additions and 14 deletions

View File

@@ -310,7 +310,7 @@ class AutomationCron(ModelSQL, ModelView):
ShipmentIn.save([shipment])
shipment._create_lots_from_fintrade()
shipment.controller = shipment.get_controller()
shipment.instructions = shipment.get_instructions()
shipment.instructions = shipment.get_instructions_html()
ShipmentIn.save([shipment])
trans_shipment.commit()
successful_shipments += 1

View File

@@ -23,6 +23,9 @@ import io
import base64
import logging
import json
import re
import html
logger = logging.getLogger(__name__)
@@ -462,26 +465,46 @@ class ShipmentIn(metaclass=PoolMeta):
for c in controllers:
if c.party.IsAvailableForControl(self):
return c.party
def get_instructions(self):
def get_instructions_html(self):
lines = [
"Hi,",
"",
"Please find details below for the requested control",
f"BL number: {self.bl_number}",
""
"<p>Hi,</p>",
"<p>Please find details below for the requested control</p>",
f"<p><strong>BL number:</strong> {self.bl_number}</p>",
]
if self.incoming_moves:
for m in self.incoming_moves:
if m.lot:
lines.append(
f"Lot nb: {m.lot.lot_name} | "
f"Net Qt: {m.lot.get_current_quantity()} {m.lot.lot_unit.symbol} | "
f"Gross Qt: {m.lot.get_current_gross_quantity()} {m.lot.lot_unit.symbol}"
"<p>"
f"<strong>Lot nb:</strong> {m.lot.lot_name} | "
f"<strong>Net Qt:</strong> {m.lot.get_current_quantity()} {m.lot.lot_unit.symbol} | "
f"<strong>Gross Qt:</strong> {m.lot.get_current_gross_quantity()} {m.lot.lot_unit.symbol}"
"</p>"
)
return "\n".join(lines)
return "".join(lines)
# def get_instructions(self):
# lines = [
# "Hi,",
# "",
# "Please find details below for the requested control",
# f"BL number: {self.bl_number}",
# ""
# ]
# if self.incoming_moves:
# for m in self.incoming_moves:
# if m.lot:
# lines.append(
# f"Lot nb: {m.lot.lot_name} | "
# f"Net Qt: {m.lot.get_current_quantity()} {m.lot.lot_unit.symbol} | "
# f"Gross Qt: {m.lot.get_current_gross_quantity()} {m.lot.lot_unit.symbol}"
# )
# return "\n".join(lines)
def _create_lots_from_fintrade(self):
t = Table('freight_booking_lots')
@@ -653,6 +676,12 @@ class ShipmentIn(metaclass=PoolMeta):
return sale_line
def html_to_text(self,html_content):
text = re.sub(r"<br\s*/?>", "\n", html_content, flags=re.IGNORECASE)
text = re.sub(r"</p\s*>", "\n\n", text, flags=re.IGNORECASE)
text = re.sub(r"<[^>]+>", "", text)
return html.unescape(text).strip()
@classmethod
@ModelView.button
def send(cls, shipments):
@@ -668,7 +697,7 @@ class ShipmentIn(metaclass=PoolMeta):
payload = {
"to": [contact[0].value],
"subject": "Request for control",
"body": sh.instructions,
"body": sh.html_to_text(sh.instructions),
# "attachments": [
# {
# "filename": "instruction.pdf",

View File

@@ -125,7 +125,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="result"/>
<newline/>
<label name="instructions"/>
<field name="instructions" widget="email" colspan="4" height="100"/>
<field name="instructions" widget="richtext" colspan="4" height="100"/>
<newline/>
<label name="returned_id"/>
<field name="returned_id"/>