main #7

Merged
admin merged 620 commits from main into dev 2026-03-29 13:03:25 +00:00
2 changed files with 53 additions and 22 deletions
Showing only changes of commit f4a53f2705 - Show all commits

View File

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

View File

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