<commit_before>##############################################################################
#
#    Copyright (C) 2018 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################
from odoo import api, models


class CompassionHold(models.Model):
    _inherit = "compassion.child"

    @api.multi
    def get_sms_sponsor_child_data(self):
        """
        Returns JSON data of the child for the mobile sponsor page
        :return: JSON data
        """
        self.ensure_one()
        result = self.read(
            [
                "name",
                "birthdate",
                "preferred_name",
                "desc_en",
                "gender",
                "image_url",
                "age",
            ]
        )[0]
        result.update(
            {
                "has_a_child": True,
                "invalid_sms_child_request": False,
                "country": self.field_office_id.country_id.name,
                "countries": self.field_office_id.search(
                    [("available_on_childpool", "=", True)]
                )
                .mapped("country_id")
                .mapped(
                    lambda country: {"value": country.code, "text": country.name}),
                "description": result["desc_en"],
            }
        )
        return result<commit_msg>CO-3375 filter countries in SMS sponsorship by state of childpool search<commit_after>##############################################################################
#
#    Copyright (C) 2018 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################
from odoo import api, models


class CompassionHold(models.Model):
    _inherit = "compassion.child"

    @api.multi
    def get_sms_sponsor_child_data(self):
        """
        Returns JSON data of the child for the mobile sponsor page
        :return: JSON data
        """
        self.ensure_one()
        result = self.read(
            [
                "name",
                "birthdate",
                "preferred_name",
                "desc_en",
                "gender",
                "image_url",
                "age",
            ]
        )[0]
        # Get crm.event from child
        hold_event = self.hold_event
        # Get set of countries of all field offices
        countries = self.field_office_id.search(
            [
                ("available_on_childpool", "=", True)
            ]
        ).mapped("country_id")
        event_countries = False
        # Get set of countries of field offices in the event
        if hold_event and hold_event.disable_childpool_search:
            event_countries = hold_event.allocate_child_ids.\
                mapped("field_office_id.country_id")
        # Intersect countries
        if event_countries:
            countries &= event_countries
        # Create dictionary of countries with value and text keys
        countries = countries.mapped(lambda country: {"value": country.code,
                                                      "text": country.name})
        # Update result
        result.update(
            {
                "has_a_child": True,
                "invalid_sms_child_request": False,
                "country": self.field_office_id.country_id.name,
                "countries": countries,
                "description": result["desc_en"],
            }
        )
        return result
{'fraction_non_alphanumeric': 0.17012779552715654, 'fraction_numerical': 0.003727369542066028, 'mean_word_length': 1.7870919881305638, 'pattern_counts': {'":': 14, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6949046', 'n_tokens_mistral': 1003, 'n_tokens_neox': 925, 'n_words': 229}