# -*- coding: utf-8 -*-

from odoo import models, fields, api
import time

class sos_Outsourcing_Return(models.Model):
    _name = 'sos_sfg_outsourcing_return_register'
    _description = 'Outsourcing Return Form'
    _rec_name = 'orr_no'
    _order = 'id desc'

    orr_no = fields.Char(string="Ref No",default=lambda self: self._generate_id(),readonly= True, required= True)
    iqi_no = fields.Many2one('sos_iqi',string="IQI No")
    iqi_date = fields.Datetime(string="IQI Date",related="iqi_no.iqi_date")
    goods_type = fields.Selection([
        ('Materials', 'Materials'),
        ('SFG', 'SFG')
    ], string='Goods Type',default="Materials",copy=True)
    service_provider_name = fields.Many2one('sos_service_providers',string="Service Provider Name", required=True,related="iqi_no.service_provider_name")
    sfg_name = fields.Many2one('sos_sfg',string="SFG Name",related="iqi_no.sfg_name")
    supplier_name = fields.Many2one('sos_suppliers', string="Supplier Name")
    material_name = fields.Many2one('sos_material',string="Material Name",related="iqi_no.material_name")
    returned_qty = fields.Integer(string="Returned Quantity",related="iqi_no.rejected_qty")
    remarks = fields.Text(string="Remarks")
    def _generate_id(self):
        sequence_util = self.env['sos_common_scripts']
        return sequence_util.generate_sequence('sos_sfg_outsourcing_return_register','ORR', 'orr_no')
