# _*_ coding: utf-8 _*_
from odoo import models, fields, api, _


class JptipMakeup(models.Model):
    _name = 'jt.makeup'

    name = fields.Char(string='補課單號')
    date = fields.Date(string='申請日期')
    student_id = fields.Many2one('jt.student', string='申請人')
    partner_id = fields.Many2one('res.partner', related="student_id.partner_id")
    class_date = fields.Date(string='課程日期')
    class_time = fields.Char(string='課程時間')
    class_name = fields.Many2one('jt.batch',string='班級名稱')
    course_line_id = fields.Many2one('jt.course.line', string='級別')
    teacher_id = fields.Many2one('jt.teacher', string='講師')
    room_id = fields.Many2one('jptip.class.room', string='教室')
    company_id = fields.Many2one(related='class_name.company_id', string='公司', store=True, readonly=True)
    sale_order_id = fields.Many2one('sale.order', string='關聯銷售訂單')
    invoice_status = fields.Selection([
        ('upselling', '超售商機'),
        ('invoiced', '已開具全額發票'),
        ('to invoice', '待開立應收憑單'),
        ('no', '沒有應收憑單需要開立')
        ], related='sale_order_id.invoice_status', string='付款狀態', store = True)
    pay_date = fields.Date(string='付款日期')
    specialist = fields.Many2one(comodel_name='res.users', string='承辦專員', default=lambda self: self.env.uid, readonly=True)

    @api.model
    def create(self, vals):
        vals['name'] = self.env['ir.sequence'].next_by_code('jt.makeup')
        # res_id.number = 'JPRQ-' + str(datetime.datetime.strptime(datetime.date.today().strftime('%Y-%m-%d'), '%Y-%m-%d').year) + res_id.number
        return super(JptipMakeup, self).create(vals)