from odoo import models, fields, api

class SosTestingParameters(models.Model):
    _name = 'sos_deliverables_config'
    _description = 'SOS FG Deliverables'
    _rec_name='fg_name'

    fg_name = fields.Selection(
            [
               ('BHMS 1.2V', 'BHMS 1.2V'), 
                ('BHMS 2V', 'BHMS 2V'), 
                ('BHMS 12V', 'BHMS 12V'),  
                ('BHMS 48V', 'BHMS 48V'),
                ('BMS-HV', 'BMS-HV'),
                ('BMS-LV 100A', 'BMS-LV 100A'), 
                ('BMS-LV 40A', 'BMS-LV 40A'), 
                ('SBMS 55A', 'SBMS 55A'),              
                ('MC 250W', 'MC 250W'),                                
                ('HeartTarang', 'HeartTarang')                
            ],
            string="Product Name",required=True)
    communication_type = fields.Selection([
        ('wired', 'Wired'),
        ('wireless', 'Wireless')
    ], string="Communication Type", default='wired')
    fg_ids = fields.One2many('sos_fg_deliverables', 'ref_id', string= 'FG Deliverables',copy=True)
    sfg_ids = fields.One2many('sos_sfg_deliverables', 'ref_id', string= 'SFG Deliverables',copy=True)
    material_ids = fields.One2many('sos_material_deliverables', 'ref_id', string='Material Deliverables',copy=True)
    installation_kit_ids = fields.One2many('sos_installation_kit_deliverables', 'ref_id', string='Installation Kit',copy=True)
    miscellaneous_ids = fields.One2many('sos_miscellaneous_deliverables', 'ref_id', string='Miscellaneous',copy=True)
    customer_name = fields.Char(string="Customer Name")
    customer_location = fields.Char(string="Customer Location")

class SOS_FG_Deliverables(models.Model):
    _name = 'sos_fg_deliverables'
    _description = 'FG Deliverables'

    sequence = fields.Integer(string="sequence")
    item_type = fields.Selection([
        ('Master Panel', 'Master Panel'),
        ('CT Module', 'CT Module'),
        ('Slave Module', 'Slave Module'),
        ('Internet Module', 'Internet Module')
    ], string="Type",default="Master Panel")
    component_id = fields.Many2one('sos_fg',string="FG Name", required=True)
    description = fields.Text(string="Description")
    quantity = fields.Float(string="Quantity",default=1)
    uom = fields.Selection([('meters', 'Meters'),('Nos', 'Nos'),('coils', 'Coils'), ('litre', 'litre'), ('kg', 'Kilogram'), ('Packs', 'Packs')], default="Nos",string="Uom")
    fg_code = fields.Char(related="component_id.fg_code",string="FG Code")
    ref_id = fields.Many2one('sos_deliverables_config', ondelete='cascade')
    add_production_cost = fields.Boolean(string="Include in Costing",default=True)
class SOS_SFG_Deliverables(models.Model):
    _name = 'sos_sfg_deliverables'
    _description = 'SFG Deliverables'

    sequence = fields.Integer(string="sequence")
    item_type = fields.Selection([
        ('Master Panel', 'Master Panel'),
        ('CT Module', 'CT Module'),
        ('Slave Module', 'Slave Module'),
        ('Internet Module', 'Internet Module')
    ], string="Type",default="Master Panel")
    component_id = fields.Many2one('sos_sfg', string="SFG Name", required=True)
    quantity = fields.Float(string="Quantity",default=1)
    description = fields.Text(string="Description")
    uom = fields.Selection([('meters', 'Meters'),('Nos', 'Nos'),('coils', 'Coils'), ('litre', 'litre'), ('kg', 'Kilogram'), ('Packs', 'Packs')], default="Nos",string="Uom")
    description = fields.Text(string="Description")
    ref_id = fields.Many2one('sos_deliverables_config', ondelete='cascade')
    add_production_cost = fields.Boolean(string="Include in Costing",default=True)
    @api.onchange('component_id')
    def _onchange_component_id(self):
        if self.component_id:
            self.description = self.component_id.description
            self.uom = self.component_id.uom
        else:
            self.description = ''
class SOS_Material_Deliverables(models.Model):
    _name = 'sos_material_deliverables'
    _description = 'Material Deliverables'

    sequence = fields.Integer(string="sequence")
    item_type = fields.Selection([
        ('Master Panel', 'Master Panel'),
        ('CT Module', 'CT Module'),
        ('Slave Module', 'Slave Module'),
        ('Internet Module', 'Internet Module')
    ], string="Type",default="Master Panel")
    component_id = fields.Many2one('sos_material', string="Material Name", required=True)
    description = fields.Text(string="Description")
    quantity = fields.Float(string="Quantity")
    uom = fields.Selection([('meters', 'Meters'),('Nos', 'Nos'),('coils', 'Coils'), ('litre', 'litre'), ('kg', 'Kilogram'), ('Packs', 'Packs')], default="Nos",string="Uom")
    currency_id = fields.Many2one('res.currency', string='Currency')
    description = fields.Text(string="Description")
    ref_id = fields.Many2one('sos_deliverables_config', ondelete='cascade')
    add_production_cost = fields.Boolean(string="Include in Costing",default=True)
    @api.onchange('component_id')
    def _onchange_component_id(self):
        if self.component_id:
            self.description = self.component_id.description
            self.uom = self.component_id.uom
        else:
            self.description = ''
class SOS_Installation_Kit_Deliverables(models.Model):
    _name = 'sos_installation_kit_deliverables'
    _description = 'Installation Kit Delieverables'

    sequence = fields.Integer(string="sequence")
    item_type = fields.Selection([
        ('Master Panel', 'Master Panel'),
        ('CT Module', 'CT Module'),
        ('Slave Module', 'Slave Module'),
        ('Internet Module', 'Internet Module')
    ], string="Type",default="Master Panel")
    component_id = fields.Many2one('sos_material', string="Material Name", required=True)
    description = fields.Text(string="Description")
    quantity = fields.Float(string="Quantity")
    uom = fields.Selection([('meters', 'Meters'),('Nos', 'Nos'),('coils', 'Coils'), ('litre', 'litre'), ('kg', 'Kilogram'), ('Packs', 'Packs')], default="Nos",string="Uom")
    ref_id = fields.Many2one('sos_deliverables_config', ondelete='cascade')
    add_production_cost = fields.Boolean(string="Include in Costing",default=True)
    @api.onchange('component_id')
    def _onchange_component_id(self):
        if self.component_id:
            self.description = self.component_id.description
            self.uom = self.component_id.uom
        else:
            self.description = ''
class SOS_Miscellaneous_Deliverables(models.Model):
    _name = 'sos_miscellaneous_deliverables'
    _description = 'Miscellaneous Delieverables'

    sequence = fields.Integer(string="sequence")
    name = fields.Char(string='Name')
    cost = fields.Float(string='Cost')
    quantity = fields.Integer(string="Quantity")
    item_type = fields.Selection([
        ('Master Panel', 'Master Panel'),
        ('CT Module', 'CT Module'),
        ('Slave Module', 'Slave Module'),
        ('Internet Module', 'Internet Module')
    ], string="Type",default="Master Panel")
    ref_id = fields.Many2one('sos_deliverables_config', ondelete='cascade')
    