This commit is contained in:
2026-02-02 15:16:37 +01:00
parent d73816285e
commit 318f9e5564
2 changed files with 52 additions and 3 deletions

View File

@@ -18,8 +18,12 @@ import datetime
from collections import defaultdict
from sql import Table
from trytond.modules.purchase_trade.service import ContractFactory
import requests
import io
import base64
import logging
import json
logger = logging.getLogger(__name__)
class Location(metaclass=PoolMeta):
@@ -428,12 +432,14 @@ class ShipmentIn(metaclass=PoolMeta):
add_bl = fields.Boolean("Add BL")
add_invoice = fields.Boolean("Add invoice")
returned_id = fields.Char("Returned ID")
result = fields.Char("Result",readonly=True)
@classmethod
def __setup__(cls):
super().__setup__()
cls._buttons.update({
'compute': {},
'send': {},
})
def get_vessel_type(self,name=None):
@@ -627,6 +633,47 @@ class ShipmentIn(metaclass=PoolMeta):
return sale_line
@classmethod
@ModelView.button
def send(cls, shipments):
Date = Pool().get('ir.date')
for sh in shipments:
sh.result = "Email not sent"
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.instructions,
# "attachments": [
# {
# "filename": "instruction.pdf",
# "content": encoded,
# "content_type": "application/pdf"
# }
# ],
"meta": {
"shipment": sh.bl_number,
"controller": sh.controller.id
}
}
response = requests.post(
"http://automation-service:8006/mail",
json=payload,
timeout=10
)
response.raise_for_status()
data = response.json()
logger.info("SEND_FROM_SHIPMENT:%s",data)
sh.result = "Email sent on " + Date.today()
sh.save()
@classmethod
@ModelView.button
def compute(cls, shipments):

View File

@@ -113,8 +113,10 @@ this repository contains the full copyright notices and license terms. -->
<page string="Weight Report" col="4" id="wr">
<label name="controller"/>
<field name="controller"/>
<label name="send_instruction"/>
<field name="send_instruction"/>
<button name="send" string="Send"/>
<newline/>
<label name="result"/>
<field name="result"/>
<newline/>
<label name="instructions"/>
<field name="instructions"/>