# Copyright 2021 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class AccAccountWizard(models.TransientModel):
    _name = "acc.account.wizard"
    _description = "Période de facturation"

    # ------------------------------------------------------
    # Fields declaration
    # ------------------------------------------------------
    start_date = fields.Date("Mois de Facturation")
    account_periodicity = fields.Selection(
        [
            ("1", "Mensuelle"),
            ("2", "Bimestriel"),
            ("3", "Trimestrielle"),
            ("6", "Semestrielle"),
            ("12", "Annuelle"),
        ],
        string="Périodicité Facturation",
        default="1",
    )
    # ------------------------------------------------------
    # SQL Constraints
    # ------------------------------------------------------

    # ------------------------------------------------------
    # Default methods
    # ------------------------------------------------------

    # ------------------------------------------------------
    # Computed fields / Search Fields
    # ------------------------------------------------------

    # ------------------------------------------------------
    # Onchange / Constraints
    # ------------------------------------------------------

    # ------------------------------------------------------
    # CRUD methods (ORM overrides)
    # ------------------------------------------------------

    # ------------------------------------------------------
    # Actions
    # ------------------------------------------------------
    def create_invoice(self):
        context = dict(self._context or {})
        if context.get("active_ids", False):
            self.env["acc.operation"].browse(context.get("active_ids")).create_account(
                self.start_date, self.account_periodicity
            )
        return {"type": "ir.actions.act_window_close"}

    # ------------------------------------------------------
    # Business methods
    # ------------------------------------------------------