20.01.26
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from trytond.pool import Pool
|
||||
from . import automation,rules,freight_booking #, document
|
||||
from . import automation,rules,freight_booking,cron #, document
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
automation.AutomationDocument,
|
||||
rules.AutomationRuleSet,
|
||||
freight_booking.FreightBookingInfo,
|
||||
cron.Cron,
|
||||
module='automation', type_='model')
|
||||
118
modules/automation/cron.py
Normal file
118
modules/automation/cron.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import requests
|
||||
from decimal import getcontext, Decimal, ROUND_HALF_UP
|
||||
from datetime import datetime
|
||||
from trytond.model import fields
|
||||
from trytond.model import (ModelSQL, ModelView)
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
import logging
|
||||
from sql import Table
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Cron(metaclass=PoolMeta):
|
||||
__name__ = 'ir.cron'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.method.selection.append(
|
||||
('automation.cron|update_shipment', "Update Shipment from freight booking info"))
|
||||
|
||||
class PriceCron(ModelSQL, ModelView):
|
||||
"Price Cron"
|
||||
__name__ = 'automation.cron'
|
||||
|
||||
frequency = fields.Selection([
|
||||
('daily', "Daily"),
|
||||
('weekly', "Weekly"),
|
||||
('monthly', "Monthly"),
|
||||
], "Frequency", required=True,
|
||||
help="How frequently rates must be updated.")
|
||||
|
||||
last_update = fields.Date("Last Update", required=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls._buttons.update({
|
||||
'run': {},
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def default_frequency(cls):
|
||||
return 'daily'
|
||||
|
||||
@classmethod
|
||||
def default_last_update(cls):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
return Date.today()
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def run(cls, crons):
|
||||
cls.update_forex(crons)
|
||||
|
||||
@classmethod
|
||||
def update_shipment(cls):
|
||||
t = Table('freight_booking_info')
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
cursor.execute(*t.select(
|
||||
t.ShippingInstructionNumber,
|
||||
t.ShippingInstructionDate,
|
||||
t.ShippingInstructionQuantity,
|
||||
t.ShippingInstructionQuantityUnit,
|
||||
t.NumberOfContainers,
|
||||
t.ContainerType,
|
||||
t.Loading,
|
||||
t.Destination,
|
||||
t.BookingAgent,
|
||||
t.Carrier,
|
||||
t.Vessel,
|
||||
t.BL_Number,
|
||||
t.ETD_Date,
|
||||
t.BL_Date,
|
||||
t.ExpectedController,
|
||||
t.Comments,
|
||||
t.FintradeBookingKey,
|
||||
))
|
||||
|
||||
for row in cursor.fetchall():
|
||||
(
|
||||
si_number,
|
||||
si_date,
|
||||
si_quantity,
|
||||
si_unit,
|
||||
container_number,
|
||||
container_type,
|
||||
loading,
|
||||
destination,
|
||||
agent,
|
||||
carrier,
|
||||
vessel,
|
||||
bl_number,
|
||||
etd_date,
|
||||
bl_date,
|
||||
controller,
|
||||
comments,
|
||||
fintrade_booking_key,
|
||||
) = row
|
||||
logger.info("ROW_FROM_CRON:%s",row)
|
||||
Location = Pool().get('stock.location')
|
||||
Vessel = Pool().get('stock.vessel')
|
||||
Party = Pool().get('party.party')
|
||||
ShipmentIn = Pool().get('stock.shipment.in')
|
||||
shipment = ShipmentIn.search(['reference','=',si_number])
|
||||
if not shipment:
|
||||
sh = ShipmentIn()
|
||||
sh.reference = si_number
|
||||
sh.from_location = Location.getLocationByName(loading,'supplier')
|
||||
sh.to_location = Location.getLocationByName(destination,'customer')
|
||||
sh.carrier = Party.getPartyByName(carrier)
|
||||
sh.vessel = Vessel.getVesselByName(vessel)
|
||||
sh.bl_number = bl_number
|
||||
sh.bl_date = bl_date
|
||||
sh.etd = etd_date
|
||||
ShipmentIn.save([sh])
|
||||
logger.info("SHIPMENT_CREATED:%s",sh)
|
||||
37
modules/automation/cron.xml
Normal file
37
modules/automation/cron.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0"?>
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="cron_view_list">
|
||||
<field name="model">automation.cron</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">cron_list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="cron_view_form">
|
||||
<field name="model">automation.cron</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">cron_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_cron_form">
|
||||
<field name="name">Update shipment from freight booking</field>
|
||||
<field name="res_model">automation.cron</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_cron_form_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="cron_view_list"/>
|
||||
<field name="act_window" ref="act_cron_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_cron_form_view2">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="cron_view_form"/>
|
||||
<field name="act_window" ref="act_cron_form"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.cron" id="cron_cron">
|
||||
<field name="method">automation.cron|update_shipment</field>
|
||||
<field name="interval_number" eval="1"/>
|
||||
<field name="interval_type">days</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -6,4 +6,5 @@ depends:
|
||||
document_incoming
|
||||
xml:
|
||||
automation.xml
|
||||
freight_booking.xml
|
||||
freight_booking.xml
|
||||
cron.xml
|
||||
@@ -22,3 +22,16 @@ class Party(metaclass=PoolMeta):
|
||||
wb = fields.Many2One('purchase.weight.basis',"Weight basis")
|
||||
association = fields.Many2One('purchase.association',"Association")
|
||||
execution = fields.One2Many('party.execution','party',"")
|
||||
|
||||
@classmethod
|
||||
def getPartyByName(cls, party, category=None):
|
||||
party = party.upper()
|
||||
p = cls.search([('name', '=', party)], limit=1)
|
||||
if p:
|
||||
return p[0].id
|
||||
else:
|
||||
p = cls()
|
||||
p.name = party
|
||||
cls.save([p])
|
||||
return p.id
|
||||
|
||||
@@ -24,16 +24,21 @@ class Location(metaclass=PoolMeta):
|
||||
__name__ = 'stock.location'
|
||||
|
||||
@classmethod
|
||||
def get_transit_id(cls):
|
||||
transit = cls.search([('name', '=', 'Transit')], limit=1)
|
||||
if transit:
|
||||
return transit[0].id
|
||||
def getLocationByName(cls, location, type):
|
||||
location = location.upper()
|
||||
loc = cls.search([('name', '=', location),('type', '=', type)], limit=1)
|
||||
if loc:
|
||||
return loc[0].id
|
||||
else:
|
||||
transit = cls()
|
||||
transit.name = 'Transit'
|
||||
transit.type = 'storage'
|
||||
cls.save([transit])
|
||||
return transit.id
|
||||
loc = cls()
|
||||
loc.name = location
|
||||
loc.type = type
|
||||
cls.save([loc])
|
||||
return loc.id
|
||||
|
||||
@classmethod
|
||||
def get_transit_id(cls):
|
||||
return cls.getLocationByName('TRANSIT','storage')
|
||||
|
||||
def is_transit(self):
|
||||
if self.name == 'Transit':
|
||||
|
||||
@@ -93,6 +93,19 @@ class Vessel(
|
||||
#logger.info("GET_INFO:%s",aux)
|
||||
return inf
|
||||
|
||||
@classmethod
|
||||
def getVesselByName(cls, vessel, imo=None):
|
||||
vessel = vessel.upper()
|
||||
v = cls.search([('vessel_name', '=', vessel)], limit=1)
|
||||
if v:
|
||||
return v[0].id
|
||||
else:
|
||||
v = cls()
|
||||
v.vessel_name = vessel
|
||||
v.vessel_imo = imo
|
||||
cls.save([v])
|
||||
return v.id
|
||||
|
||||
@classmethod
|
||||
def remover(cls,tr = ""):
|
||||
char_to_keep = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ")
|
||||
|
||||
Reference in New Issue
Block a user