Skip to content
Snippets Groups Projects
account_invoice_report.py 2.98 KiB
Newer Older
# Copyright 2023 Le Filament (https://le-filament.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import api, fields, models


class AccountInvoiceReport(models.Model):
    _inherit = "account.invoice.report"

    # ==== Invoice fields ====
    contract_id = fields.Many2one(
        comodel_name="hall.contract",
        string="Contrat",
        readonly=True,
    )
    period_start = fields.Date("Date loyer", readonly=True)
    month_revenue = fields.Float(
        "CA Mensuel (HT)",
        readonly=True,
    )
    month_b2b_revenue = fields.Float(
        "CA Mensuel B2B (HT)",
        readonly=True,
    )
    month_ref_revenue = fields.Float(
        string="CA Mensuel de référence (HT)",
        readonly=True,
    )

    # ==== Invoice line fields ====
    virtuous_discount_id = fields.Many2one(
        comodel_name="hall.contract.discount",
        string="Loyer vertueux",
        readonly=True,
    )

    # ==== Contract fields ====
    hall_id = fields.Many2one(
        comodel_name="hall.hall",
        string="Site",
        readonly=True,
    )
    commercial_name = fields.Char("Enseigne", readonly=True)
    type_job = fields.Selection(
        selection=[
            ("food", "Restauration"),
            ("bar", "Bar"),
            ("hybrid", "Hybride"),
            ("food_scholl", "Food school"),
            ("pop_up", "Pop up"),
        ],
        string="Type d'enseigne",
        readonly=True,
    )

    # ==== Discount fields ====
    date_discount = fields.Date("Date loyer vertueux", readonly=True)
    discount = fields.Float("Réduction", readonly=True)

    _depends = {
        "account.move": [
            "contract_id", "period_start", "month_revenue", "month_b2b_revenue",
            "month_ref_revenue",
        ],
        "account.move.line": ["virtuous_discount_id",],
        "hall.contract": ["hall_id", "commercial_name", "type_job"],
        "hall.contract.discount": ["date_discount", "date_discount"],
    }

    @api.model
    def _select(self):
        query_select = super(AccountInvoiceReport, self)._select()
        query_select += """
        ,
        move.contract_id as contract_id,
        move.period_start as period_start,
        move.month_revenue as month_revenue,
        move.month_b2b_revenue as month_b2b_revenue,
        move.month_ref_revenue as month_ref_revenue,
        line.virtuous_discount_id as virtuous_discount_id,
        contract.hall_id as hall_id,
        contract.commercial_name as commercial_name,
        contract.type_job as type_job,
        discount.date_discount as date_discount,
        discount.discount as discount
        """
        return query_select

    @api.model
    def _from(self):
        query_from = super(AccountInvoiceReport, self)._from()
        query_from += """
            LEFT JOIN hall_contract contract ON contract.id = move.contract_id
            LEFT JOIN hall_contract_discount discount
                ON discount.id = line.virtuous_discount_id
        """
        return query_from