from odoo import models, fields, api
from datetime import datetime

class MaterialBackupExportWizard(models.TransientModel):
    _name = 'material_backup_export'
    _description = 'Export Backup'

    def _get_year_selection(self):
        return [(str(y), str(y)) for y in range(2024, datetime.now().year)]

    year = fields.Selection(
        selection=lambda self: self._get_year_selection(),
        string="Financial Year",
        required=True
    )
    item_type = fields.Selection([
        ('material', 'Materials'),
        ('sfg', 'Semi-Finished Goods'),
        ('fg', 'Finished Goods')
    ], string="Item Type", required=True,default="material")
    def download_excel(self):
        return {
            'type': 'ir.actions.act_url',
            'url': f'/download/material/backup/{self.year}/{self.item_type}',
            'target': 'new',
        }
