
from odoo import models, fields, api
from odoo.exceptions import UserError
from datetime import date, timedelta


class SOS_SPENCO_Summary_Week(models.Model):
    _name = 'sos_spenco_summary_week_wise'
    _description = 'Sosaley SPENCO Summary Week Wise'

    sales_executive = fields.Many2one('res.users', string='Sales Executive')
    spenco_status = fields.Selection([('Suspects','Suspects'),('Prospects','Prospects'),('Engaged','Engaged'),('Negotiation','Negotiation'),('Commercial Order','Commercial Order')],string='Current State',compute='_compute_is_latest',store=True)
    currency_id = fields.Many2one(
    'res.currency',
    string='Currency',
    default=lambda self: self.env['res.currency'].search([('name', '=', 'INR')], limit=1).id or False
)
    opening_cases_count = fields.Integer(string="Opening")
    opening_cases_value = fields.Monetary(currency_field='currency_id',string="Opening Value")
    downgrade_cases_count = fields.Integer(string="Downgrade")
    downgrade_cases_value = fields.Monetary(currency_field='currency_id',string="Downgrade Value")
    upgrade_cases_count = fields.Integer(string="Upgrade")
    upgrade_cases_value = fields.Monetary(currency_field='currency_id',string="Upgrade Value")
    new_cases_count = fields.Integer(string="New")
    new_cases_value = fields.Monetary(currency_field='currency_id',string="New Value")
    closing_cases_count = fields.Integer(string="Closing")
    closing_cases_value = fields.Monetary(currency_field='currency_id',string="Closing Value")
    entered_date = fields.Date(string="Date")
    week_number = fields.Char(string="Week")
    
class SOS_SPENCO_Summary_Month(models.Model):
    _name = 'sos_spenco_summary_month_wise'
    _description = 'Sosaley SPENCO Summary Month Wise'

    sales_executive = fields.Many2one('res.users', string='Sales Executive')
    spenco_status = fields.Selection([('Suspects','Suspects'),('Prospects','Prospects'),('Engaged','Engaged'),('Negotiation','Negotiation'),('Commercial Order','Commercial Order')],string='Current State',compute='_compute_is_latest',store=True)
    currency_id = fields.Many2one(
    'res.currency',
    string='Currency',
    default=lambda self: self.env['res.currency'].search([('name', '=', 'INR')], limit=1).id or False
)
    opening_cases_count = fields.Integer(string="Opening")
    opening_cases_value = fields.Monetary(currency_field='currency_id',string="Opening Value")
    downgrade_cases_count = fields.Integer(string="Downgrade")
    downgrade_cases_value = fields.Monetary(currency_field='currency_id',string="Downgrade Value")
    upgrade_cases_count = fields.Integer(string="Upgrade")
    upgrade_cases_value = fields.Monetary(currency_field='currency_id',string="Upgrade Value")
    new_cases_count = fields.Integer(string="New")
    new_cases_value = fields.Monetary(currency_field='currency_id',string="New Value")
    closing_cases_count = fields.Integer(string="Closing")
    closing_cases_value = fields.Monetary(currency_field='currency_id',string="Closing Value")
    entered_date = fields.Date(string="Date")
    month_number = fields.Char(string="Month")

class SOS_SPENCO_Summary_Quarter(models.Model):
    _name = 'sos_spenco_summary_quarter_wise'
    _description = 'Sosaley SPENCO Summary Quarter Wise'

    sales_executive = fields.Many2one('res.users', string='Sales Executive')
    spenco_status = fields.Selection([('Suspects','Suspects'),('Prospects','Prospects'),('Engaged','Engaged'),('Negotiation','Negotiation'),('Commercial Order','Commercial Order')],string='Current State',compute='_compute_is_latest',store=True)
    currency_id = fields.Many2one(
    'res.currency',
    string='Currency',
    default=lambda self: self.env['res.currency'].search([('name', '=', 'INR')], limit=1).id or False
)
    opening_cases_count = fields.Integer(string="Opening")
    opening_cases_value = fields.Monetary(currency_field='currency_id',string="Opening Value")
    downgrade_cases_count = fields.Integer(string="Downgrade")
    downgrade_cases_value = fields.Monetary(currency_field='currency_id',string="Downgrade Value")
    upgrade_cases_count = fields.Integer(string="Upgrade")
    upgrade_cases_value = fields.Monetary(currency_field='currency_id',string="Upgrade Value")
    new_cases_count = fields.Integer(string="New")
    new_cases_value = fields.Monetary(currency_field='currency_id',string="New Value")
    closing_cases_count = fields.Integer(string="Closing")
    closing_cases_value = fields.Monetary(currency_field='currency_id',string="Closing Value")
    entered_date = fields.Date(string="Date")
    quarter_number = fields.Char(string="Quarter")

class SOS_SPENCO_Summary_Year(models.Model):
    _name = 'sos_spenco_summary_year_wise'
    _description = 'Sosaley SPENCO Summary Year Wise'

    sales_executive = fields.Many2one('res.users', string='Sales Executive')
    spenco_status = fields.Selection([('Suspects','Suspects'),('Prospects','Prospects'),('Engaged','Engaged'),('Negotiation','Negotiation'),('Commercial Order','Commercial Order')],string='Current State',compute='_compute_is_latest',store=True)
    currency_id = fields.Many2one(
    'res.currency',
    string='Currency',
    default=lambda self: self.env['res.currency'].search([('name', '=', 'INR')], limit=1).id or False
)
    opening_cases_count = fields.Integer(string="Opening")
    opening_cases_value = fields.Monetary(currency_field='currency_id',string="Opening Value")
    downgrade_cases_count = fields.Integer(string="Downgrade")
    downgrade_cases_value = fields.Monetary(currency_field='currency_id',string="Downgrade Value")
    upgrade_cases_count = fields.Integer(string="Upgrade")
    upgrade_cases_value = fields.Monetary(currency_field='currency_id',string="Upgrade Value")
    new_cases_count = fields.Integer(string="New")
    new_cases_value = fields.Monetary(currency_field='currency_id',string="New Value")
    closing_cases_count = fields.Integer(string="Closing")
    closing_cases_value = fields.Monetary(currency_field='currency_id',string="Closing Value")
    entered_date = fields.Date(string="Date")
    year = fields.Char(string="Year")