<commit_before># Copyright 2018 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models


class PaymentTransaction(models.Model):

    _inherit = "payment.transaction"

    membership_ids = fields.Many2many(
        string="Memberships",
        comodel_name="membership.line",
    )
    membership_request_ids = fields.Many2many(
        string="Membership Requests",
        comodel_name="membership.request",
    )
    display_reference = fields.Char(compute="_compute_display_reference")

    def write(self, vals):
        if vals.get("state") == "done" and self.membership_ids:
            self._mark_membership_as_paid(vals.get("acquirer_reference"))
        res = super().write(vals)
        if vals.get("state") == "done" and self.membership_request_ids:
            # may update the result state
            self.membership_request_ids.onchange_partner_id()
        return res

    def _post_process_after_done(self):
        res = super(PaymentTransaction, self)._post_process_after_done()
        tx_done = self.filtered(lambda s: s.state == "done" and s.membership_request_ids)
        if tx_done:
            # auto-validate after payment, if asked
            for mr in tx_done.mapped("membership_request_ids").filtered(
                lambda s: s.auto_validate_after_payment
            ):
                failure_reason = mr._auto_validate(True)
                if failure_reason:
                    mr._create_note(
                        _("Autovalidation after payment failed"),
                        _("Autovalidation after payment failed. Reason of failure: %s")
                        % failure_reason,
                    )
        return res

    @api.depends("reference", "membership_ids", "membership_ids.reference")
    def _compute_display_reference(self):
        for tx in self:
            reference = tx.reference
            if tx.membership_ids and tx.membership_ids.mapped("reference"):
                reference = tx.membership_ids.mapped("reference")[
                    0
                ]  # should be only one
            elif tx.membership_request_ids and tx.membership_request_ids.mapped(
                "reference"
            ):
                reference = tx.membership_request_ids.mapped("reference")[
                    0<commit_msg>pre-commit<commit_after># Copyright 2018 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models


class PaymentTransaction(models.Model):

    _inherit = "payment.transaction"

    membership_ids = fields.Many2many(
        string="Memberships",
        comodel_name="membership.line",
    )
    membership_request_ids = fields.Many2many(
        string="Membership Requests",
        comodel_name="membership.request",
    )
    display_reference = fields.Char(compute="_compute_display_reference")

    def write(self, vals):
        if vals.get("state") == "done" and self.membership_ids:
            self._mark_membership_as_paid(vals.get("acquirer_reference"))
        res = super().write(vals)
        if vals.get("state") == "done" and self.membership_request_ids:
            # may update the result state
            self.membership_request_ids.onchange_partner_id()
        return res

    def _post_process_after_done(self):
        res = super(PaymentTransaction, self)._post_process_after_done()
        tx_done = self.filtered(
            lambda s: s.state == "done" and s.membership_request_ids
        )
        if tx_done:
            # auto-validate after payment, if asked
            for mr in tx_done.mapped("membership_request_ids").filtered(
                lambda s: s.auto_validate_after_payment
            ):
                failure_reason = mr._auto_validate(True)
                if failure_reason:
                    mr._create_note(
                        _("Autovalidation after payment failed"),
                        _("Autovalidation after payment failed. Reason of failure: %s")
                        % failure_reason,
                    )
        return res

    @api.depends("reference", "membership_ids", "membership_ids.reference")
    def _compute_display_reference(self):
        for tx in self:
            reference = tx.reference
            if tx.membership_ids and tx.membership_ids.mapped("reference"):
                reference = tx.membership_ids.mapped("reference")[
                    0
                ]  # should be only one
            elif tx.membership_request_ids and tx.membership_request_ids.mapped(
                "reference"
            ):
                reference = tx.membership_request_ids.mapped("reference")[
                    0
{'fraction_non_alphanumeric': 0.09349162603349587, 'fraction_numerical': 0.00423998304006784, 'mean_word_length': 2.1286472148541113, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4149901', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1276, 'n_words': 260}