# _*_ coding: utf-8 _*_
# Author: JasonWu( Jaronemo@msn.com)
from odoo import models, fields, api

class ProductProduct(models.Model):
    _inherit = "product.template"

    batch_id = fields.Many2one('jt.batch', string='班级的ID碼')
    start_class_course = fields.Many2one('jt.course.line', string='級數')
    course_id = fields.Many2one('jt.course', string='課程系列')
    classes = fields.Integer(string='課堂數量')
    offer_classes = fields.Integer(string='前不算堂數')
    suffix_offer_classes = fields.Integer(string='後不算堂數')
    is_course = fields.Boolean(string='是否為課程')
    is_amortization = fields.Boolean(string='以課程進度進行攤銷')

# class JptipCourse(models.Model):
#     _inherit = "jt.course"
#
#     @api.model
#     def create(self, vals):
#         res = super(JptipCourse, self).create(vals)
#         product_cat_vals = {
#             'name': vals['name'],
#             'parent_id': 1,
#         }
#         self.env['product.category'].create(product_cat_vals)
#         return res

# class JptipCourseLine(models.Model):
#     _inherit = 'jt.course.line'
#
#     @api.model
#     def create(self, vals):
#         course_line = super(JptipCourseLine, self).create(vals)
#         course = self.env['jt.course'].search([('id', '=', vals['course_id'])])
#         product_vals = {
#             'name': '%s%s' % (course.name, vals['code']),
#             'default_code': vals['code'],
#             'categ_id': self.env['product.category'].search([('name', '=', course.name)]).id,
#             'course_id': vals['course_id'],
#             'type': 'service',
#             'start_class_course': course_line.id
#         }
#         self.env['product.product'].create(product_vals)
#         return course_line