from trytond.model import ModelSQL, ModelView, fields
from trytond.pool import PoolMeta
from trytond.exceptions import UserError
from trytond.modules.purchase_trade.purchase import (TRIGGERS)

__all__ = ['PaymentTerm', 'PaymentTermLine']
__metaclass__ = PoolMeta


class PaymentTerm(metaclass=PoolMeta):
    __name__ = 'account.invoice.payment_term'

    # champs supplémentaires pour gérer vos Mixed Terms
    is_mixed = fields.Boolean('Is Mixed Term', help="Indicates a mixed payment term")


class PaymentTermLine(metaclass=PoolMeta):
    __name__ = 'account.invoice.payment_term.line'

    # champs supplémentaires pour Atomic Term
    trigger_event = fields.Selection(TRIGGERS, 'Trigger Event')

    term_type = fields.Selection([
        (None, ''),
        ('advance', 'Advance'),
        ('cad', 'CAD'),
        ('open', 'Open'),
        ('lc', 'LC'),
        ('other', 'Other'),
    ], 'Term Type')

    trigger_offset = fields.Integer('Trigger Offset')
    offset_unit = fields.Selection([
        (None, ''),
        ('calendar', 'Calendar Days'),
        ('business', 'Business Days'),
    ], 'Offset Unit')

    eom_flag = fields.Boolean('EOM Flag')
    eom_mode = fields.Selection([
        (None, ''),
        ('standard', 'Standard'),
        ('before', 'Before EOM'),
        ('after', 'After EOM'),
    ], 'EOM Mode')

    risk_classification = fields.Selection([
        (None, ''),
        ('fully_secured', 'Fully Secured'),
        ('partially_secured', 'Partially Secured'),
        ('unsecured', 'Unsecured'),
    ], 'Risk Classification')
