# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Bool, Eval, Id
from trytond.model import (ModelSQL, ModelView)

class Component(ModelSQL, ModelView):
    "Component"
    __name__ = 'price.component'

    line = fields.Many2One('purchase.line',"Line")
    fix_type = fields.Many2One('price.fixtype',"Fixation type")
    ratio = fields.Numeric("%")
    price_index = fields.Many2One('price.price',"Price index")
    price_value = fields.Numeric("Price")
    calendar = fields.Many2One('price.calendar',"Calendar")
    rule = fields.Many2One('price.rule',"Price rules")
    nbdays = fields.Integer("Nb days")
    quota = fields.Numeric("Quota")

class Rule(ModelSQL,ModelView):
    "Rule"
    __name__ = 'price.rule'

    name = fields.Char("Name")
    triggers = fields.One2Many('price.trigger','rule',"Triggers")
    periods = fields.One2Many('price.period','rule',"Periods")

class Trigger(ModelSQL,ModelView):
    "Trigger"
    __name__ = "Trigger"

    rule = fields.Many2One('price.rule',"Trigger")
    trigger = fields.Selection([
        (None, ''),
        ('bldate', 'BL date'),
        ('ctdate', 'Contract date'),
    ], 'Trigger')
    before = fields.Integer("Nb days before")
    after = fields.Integer("Nb days after")

class Period(ModelSQL,ModelView):
    "Period"
    __name__ = 'price.period'

    rule = fields.Many2One('price.rule',"Rules")
    from = fields.Date("From")
    to = fields.Date("To")

class Pricing(ModelSQL,ModelView):
    "Pricing"
    __name__ = 'price.pricing'

    pricing_date = fields.Date("Date")
    price_component = fields.Many2One('price.component',"Component")
    quantity = fields.Numeric("Qt")
    settl_price = fields.Numeric("Settl. price")
    fixed_qt = fields.Numeric("Fixed qt")
    fixed_qt_price = fields.Numeric("Fixed qt price")
    unfixed_qt = fields.Numeric("Unfixed qt")
    unfixed_qt_price = fields.Numeric("Unfixed qt price")
    eod_price = fields.Numeric("EOD price")
