from odoo import models, fields, api

class MaterialType(models.Model):
    _name = 'sos_material_types'
    _description = 'Material Type'

    name = fields.Char(string="Material Type", required=True)
    sub_type_ids = fields.One2many('sos_material_sub_types', 'material_type_id', string="Sub Types")

    _sql_constraints = [
        ('name_unique', 'UNIQUE(name)', 'The Material Type must be unique!')
    ]

class MaterialSubType(models.Model):
    _name = 'sos_material_sub_types'
    _description = 'Material Sub Type'

    name = fields.Char(string="Sub Type Name", required=True)
    material_type_id = fields.Many2one('sos_material_types', string="Material Type", required=True)
    prefix = fields.Char(string="Prefix Code", required=True)
