from trytond.model import ModelSQL, fields

class ExecutionFollowUp(ModelSQL):
    "Execution Follow Up"
    __name__ = 'execution.automation'

    port_of_loading = fields.Char("Port of Loading")
    fb_loading = fields.Char("FB Loading")
    warehouse = fields.Char("Warehouse")
    origin = fields.Char("Origin")
    agent = fields.Char("Agent")
    operator = fields.Char("Operator")

    fintrade_lc_nb = fields.Char("Fintrade LC Nb")
    lc_number = fields.Char("LC Number")
    si = fields.Char("SI")

    port_of_destination = fields.Char("Port of Destination")
    fb_destination = fields.Char("FB Destination")
    status = fields.Char("Status")

    etd_date = fields.Date("ETD Date")
    bl_date = fields.Date("BL Date")
    etd_sob = fields.Date("ETD SOB")

    sale_contract_no = fields.Char("Sale Contract No")
    customer = fields.Char("Customer")
    elt_quantity = fields.Float("Elt Quantity")

    number_of_container = fields.Integer("Containers")
    vessel = fields.Char("Vessel")
    shipping_company = fields.Char("Shipping Company")
    booking_ref = fields.Char("Booking Ref")
    freight_forwarder = fields.Char("Freight Forwarder")

    instrument_status = fields.Char("Instrument Status")
    ip_date = fields.Date("IP Date")
    ip_status = fields.Char("IP Status")
    latest_shipment_date = fields.Date("Latest Shipment Date")

    countersigned = fields.Boolean("Countersigned")
    comments = fields.Text("Comments")
    docs_internal_comments = fields.Text("Docs Internal Comments")

    alloc_quantity = fields.Float("Allocated Quantity")
    si_comments = fields.Text("SI Comments")
    is_archived = fields.Boolean("Archived")

    price_cont = fields.Numeric("Price / Cont")
    price_cont_curr = fields.Char("Currency")

    ct_period_start = fields.Date("CT Start")
    ct_period_end = fields.Date("CT End")

    lsd_check = fields.Char("LSD Check")
    bl2lsd_delta = fields.Integer("BL → LSD Delta")

    fintrade_booking = fields.Char("Fintrade Booking")
    alloc_unit_price = fields.Numeric("Alloc Unit Price")
    alloc_price_curr = fields.Char("Alloc Price Curr")
    alloc_price_unit = fields.Char("Alloc Price Unit")

    left_time = fields.Integer("Days Left")

    @classmethod
    def table_query(cls):
        return (
            "SELECT "
            "row_number() OVER () AS id, "
            "* "
            "FROM singa_execution_follow_up"
        )
