Skip to content
Snippets Groups Projects
account_move.py 3.31 KiB
Newer Older
  • Learn to ignore specific revisions
  • # © 2020 Le Filament (<http://www.le-filament.com>)
    # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
    
    
    
    from odoo import api, fields, models
    
    
    class ScopAccountMove(models.Model):
        _inherit = "account.move"
    
        @api.model
        def default_get(self, fields):
            """
            Attribue la valeur du journal des cotisations par défaut si la facture
            est de type 'is_contribution'
            Affecte le type 'is_contribution' par défaut si la facture est sur le
            journal des cotisations
            :param fields:
            :return:
            """
            res = super(ScopAccountMove, self).default_get(fields)
            if res.get("is_contribution"):
    
                res["journal_id"] = self.env.company.contribution_journal_id.id
    
            else:
                if (
                    res.get("journal_id")
    
                    == self.env.company.contribution_journal_id.id
    
                ):
                    res["is_contribution"] = True
            return res
    
        liasse_fiscale_id = fields.Many2one(
            comodel_name="scop.liasse.fiscale", string="Liasse Fiscale"
        )
        year = fields.Integer("Année de cotisation")
        is_contribution = fields.Boolean("Cotisation", default=False)
        type_contribution_id = fields.Many2one(
            comodel_name="scop.contribution.type",
            string="Type de cotisation",
            readonly=True,
        )
        partner_ur_id = fields.Many2one(
            comodel_name="union.regionale",
            string="UR Adhérent",
            related="partner_id.ur_id",
            store=True,
        )
        partner_member_number = fields.Char(
            string="N° Adhérent",
            related="partner_id.member_number",
        )
        is_sdd = fields.Boolean(
            "Au prélèvement", compute="_compute_is_sdd", search="_search_is_sdd"
        )
    
        # ------------------------------------------------------
        # Computed field
        # ------------------------------------------------------
        def _compute_is_sdd(self):
            sdd_id = self.env.ref("account_banking_sepa_direct_debit.sepa_direct_debit").id
            for invoice in self:
                if (
                    invoice.payment_mode_id
                    and invoice.payment_mode_id.payment_method_id.id == sdd_id
                ):
                    invoice.is_sdd = True
                else:
                    invoice.is_sdd = False
    
        def _search_is_sdd(self, operator, value):
            recs = self.search([]).filtered(lambda x: x.is_sdd is True)
            if recs:
                return [("id", "in", [x.id for x in recs])]
    
        # ------------------------------------------------------
        # Override Parent
        # ------------------------------------------------------
    
        def _compute_payments_widget_to_reconcile_info(self):
            """
            Modifie les données de sortie du JSON de réconciliation pour ajouter
            la date d'échéance
            """
            super()._compute_payments_widget_to_reconcile_info()
            for move in self:
                info = json.loads(move.invoice_outstanding_credits_debits_widget)
                if info:
                    lines_info = info["content"]
                    for line in lines_info:
                        line_id = move.line_ids.browse(line.get("id"))
                        line.update(
                            {"date_maturity": fields.Date.to_string(line_id.date_maturity)}
                        )
                    move.invoice_outstanding_credits_debits_widget = json.dumps(info)