# -*- coding: utf-8 -*-
# /#############################################################################
#
#    Stephan Neuhausen.
#    Copyright (C) 20014-TODAY Stephan Neuhausen iad.de.
#
# /#############################################################################

from openerp import models, fields

from openerp.addons.training_management.models.model_names import ModelNames


class ConcreteDegree(models.Model):
    _name = ModelNames.CONCRETE_DEGREE

    CONTEXT_KEY__PUBLISHED_BY_IAD_ONLY = "published_by_iad_only"

    abstract_degree_id = fields.Many2one(
        comodel_name=ModelNames.ABSTRACT_DEGREE,
        required=True,
        domain=lambda self: self._domain__abstract_degree_id(),
        ondelete="restrict",
        string="Abschluss",
    )
    date = fields.Date(
        string="Datum",
        default=lambda self: fields.Date.today(),
    )
    evaluation = fields.Text(string="Beurteilung")
    number_of_exams = fields.Integer(string=u"Anz. Prüfungen", default=0)
    is_included_in_prints = fields.Boolean(string=u"Im Ausdruck enthalten", default=True)
    education_plan_id = fields.Many2one(
        comodel_name=ModelNames.EDUCATION_PLAN,
        ondelete="cascade",
    )
    partner_id = fields.Many2one(
        comodel_name=ModelNames.PARTNER,
        ondelete="cascade",
    )
    course_id = fields.Many2one(
        comodel_name=ModelNames.TEACHING,
        ondelete="cascade",
    )

    def _domain__abstract_degree_id(self):
        context = self.env.context
        if context.get(self.CONTEXT_KEY__PUBLISHED_BY_IAD_ONLY, False):
            return [('is_publishable_by_iad', '=', True)]
        else:
            return []
