Skip to content
Snippets Groups Projects
account_move.py 4.67 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.user.company_id.contribution_journal_id.id
            else:
                if (
                    res.get("journal_id")
                    == self.env.user.company_id.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
        # ------------------------------------------------------
        # TODO: check if necessary
        # def _get_outstanding_info_JSON(self):
        #     super(ScopAccountMove, self)._get_outstanding_info_JSON()
        #     info = json.loads(self.outstanding_credits_debits_widget)
        #     if info:
        #         values = info.get("content", False)
        #         if self.state == "open" and values:
        #             domain = [
        #                 ("account_id", "=", self.account_id.id),
        #                 (
        #                     "partner_id",
        #                     "=",
        #                     self.env["res.partner"]
        #                     ._find_accounting_partner(self.partner_id)
        #                     .id,
        #                 ),
        #                 ("reconciled", "=", False),
        #                 ("move_id.state", "=", "posted"),
        #                 "|",
        #                 "&",
        #                 ("amount_residual_currency", "!=", 0.0),
        #                 ("currency_id", "!=", None),
        #                 "&",
        #                 ("amount_residual_currency", "=", 0.0),
        #                 "&",
        #                 ("currency_id", "=", None),
        #                 ("amount_residual", "!=", 0.0),
        #             ]
        #             if self.type in ("out_invoice", "in_refund"):
        #                 domain.extend([("credit", ">", 0), ("debit", "=", 0)])
        #             else:
        #                 domain.extend([("credit", "=", 0), ("debit", ">", 0)])
        #             lines = self.env["account.move.line"].search(domain)
        #             for value in values:
        #                 for line in lines:
        #                     if value.get("id") == line.id:
        #                         value.update(
        #                             {
        #                                 "date_maturity": datetime.strftime(
        #                                     line.date_maturity, "%d/%m/%Y"
        #                                 ),
        #                                 "invoice": line.invoice_id.number,
        #                             }
        #                         )
        #             self.outstanding_credits_debits_widget = json.dumps(info)