02.02.26
This commit is contained in:
@@ -18,8 +18,12 @@ import datetime
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from sql import Table
|
from sql import Table
|
||||||
from trytond.modules.purchase_trade.service import ContractFactory
|
from trytond.modules.purchase_trade.service import ContractFactory
|
||||||
|
import requests
|
||||||
|
import io
|
||||||
|
import base64
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Location(metaclass=PoolMeta):
|
class Location(metaclass=PoolMeta):
|
||||||
@@ -428,12 +432,14 @@ class ShipmentIn(metaclass=PoolMeta):
|
|||||||
add_bl = fields.Boolean("Add BL")
|
add_bl = fields.Boolean("Add BL")
|
||||||
add_invoice = fields.Boolean("Add invoice")
|
add_invoice = fields.Boolean("Add invoice")
|
||||||
returned_id = fields.Char("Returned ID")
|
returned_id = fields.Char("Returned ID")
|
||||||
|
result = fields.Char("Result",readonly=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
super().__setup__()
|
super().__setup__()
|
||||||
cls._buttons.update({
|
cls._buttons.update({
|
||||||
'compute': {},
|
'compute': {},
|
||||||
|
'send': {},
|
||||||
})
|
})
|
||||||
|
|
||||||
def get_vessel_type(self,name=None):
|
def get_vessel_type(self,name=None):
|
||||||
@@ -627,6 +633,47 @@ class ShipmentIn(metaclass=PoolMeta):
|
|||||||
|
|
||||||
return sale_line
|
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
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
def compute(cls, shipments):
|
def compute(cls, shipments):
|
||||||
|
|||||||
@@ -113,8 +113,10 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<page string="Weight Report" col="4" id="wr">
|
<page string="Weight Report" col="4" id="wr">
|
||||||
<label name="controller"/>
|
<label name="controller"/>
|
||||||
<field name="controller"/>
|
<field name="controller"/>
|
||||||
<label name="send_instruction"/>
|
<button name="send" string="Send"/>
|
||||||
<field name="send_instruction"/>
|
<newline/>
|
||||||
|
<label name="result"/>
|
||||||
|
<field name="result"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<label name="instructions"/>
|
<label name="instructions"/>
|
||||||
<field name="instructions"/>
|
<field name="instructions"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user