diff --git a/modules/automation/cron.py b/modules/automation/cron.py index 1c5c491..6a623d4 100644 --- a/modules/automation/cron.py +++ b/modules/automation/cron.py @@ -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 diff --git a/modules/purchase_trade/stock.py b/modules/purchase_trade/stock.py index 6d70b8d..1302cf4 100755 --- a/modules/purchase_trade/stock.py +++ b/modules/purchase_trade/stock.py @@ -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 = [ "

Hi,

", "

Please find details below for the requested control

", f"

BL number: {self.bl_number}

", + f"

ETA: {self.eta}

", + f"

Vessel: {vessel}

", ] 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_line.symbol} | " - f"Gross Qt: {m.lot.get_current_gross_quantity()} {m.lot.lot_unit_line.symbol}" - "

" - ) + 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("

" + f"Customer: {customer}" + "

" + ) + lines.append("

" + f"Invoice Nb: {inv_nb}" + "

" + ) + lines.append("

" + f"Invoice Date: {inv_date}" + "

" + ) + lines.append( + "

" + f"Nb Bales: {tot_bale} | " + f"Net Qt: {tot_net} {unit} | " + f"Gross Qt: {tot_gross} {unit}" + "

" + ) 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"", "\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