<commit_before>import datetime

__author__ = 'tbri'

from openerp import models, fields, api, _
from openerp.exceptions import except_orm, Warning, RedirectWarning
import openerp.addons.decimal_precision as dp
import logging

_logger = logging.getLogger(__name__)

class SponsoredChild(models.Model):
    _inherit = 'res.partner'

    @api.one
    @api.depends('sponsors')
    def _calc_needs_sponsor(self):
        """
        This is true if we have no sponsorships, or they ara all ended.
        """
        print "NEEDS SPONSOR 1", len(self.sponsors)
        for s in self.sponsors:
            print "NEEDS SPONSOR", s.start_date, s.end_date
        if not len(self.sponsors):
            self.needs_sponsor = True
            return

        needs_sponsor = True
        for sponsorship in self.sponsors:
            print "NEEDS SPONSOR", sponsorship.end_date
            if not sponsorship.end_date:
                needs_sponsor = False
                print "NEEDS SPONSOR NOT"
        self.needs_sponsor = needs_sponsor

    @api.one
    @api.depends('date_of_birth', 'birthyear')
    def _calc_age(self):
        if not self.sponsored_child:
            self.probable_age = None
            return

        now = datetime.date.today().year
        if self.date_of_birth:
            dob_year =  datetime.datetime.strptime(self.date_of_birth,'%Y-%m-%d').year
            self.probable_age = now - dob_year
        elif self.birthyear:
            self.probable_age = now - self.birthyear
        else:
            raise Warning(_('Either birthdate or birth year must be set.'))

    @api.one
    @api.depends('previous_images')
    def _get_number_of_images(self):
        number = 0
        if self.image:
            number += 1

        if not self.previous_images:
            self.number_of_images = number
        else:
            self.number_of_images = number + len(self.previous_images)

    def included_visits(self, all_visits):
        return filter(lambda visit: visit.include_in_letter, all_visits)

    def sponsor_names(self):
        retval = []
        for sponsorship in self.sponsors:
            if sponsorship.sub_sponsor_id:
                retval.append(sponsorship.sub_sponsor_id.name)
            else:
                retval.append(sponsorship.sponsor_id.name)
        return retval

    @api.one
    def _get_address(self):
        self.child_address = self.village.child_address

    @api.one
    def _calc_report_filename(self):
        self.report_index = self.report_index + 1
        self.report_filename = 'sponsorship-%s-2014-%d' % (self.child_ident, self.report_index)

    @api.one
    def _calc_visible_images(self):
        rv = []
        for image in self.image_ids:
            if not image.visible:
                continue
            rv.append(image.id)
        self.visible_image_ids = rv

    @api.multi
    @api.depends('last_schoolclass_update')
    def _calc_schoolclass_update_year(self):
        for child in self:
            if child.last_schoolclass_update:
                los_datos = fields.Date.from_string(child.last_schoolclass_update)<commit_msg>Not making that module after all.<commit_after>import datetime

__author__ = 'tbri'

from openerp import models, fields, api, _
from openerp.exceptions import except_orm, Warning, RedirectWarning
import openerp.addons.decimal_precision as dp
import logging

_logger = logging.getLogger(__name__)

class SponsoredChild(models.Model):
    _inherit = 'res.partner'

    @api.one
    @api.depends('sponsors')
    def _calc_needs_sponsor(self):
        """
        This is true if we have no sponsorships, or they ara all ended.
        """
        print "NEEDS SPONSOR 1", len(self.sponsors)
        for s in self.sponsors:
            print "NEEDS SPONSOR", s.start_date, s.end_date
        if not len(self.sponsors):
            self.needs_sponsor = True
            return

        needs_sponsor = True
        for sponsorship in self.sponsors:
            print "NEEDS SPONSOR", sponsorship.end_date
            if not sponsorship.end_date:
                needs_sponsor = False
                print "NEEDS SPONSOR NOT"
        self.needs_sponsor = needs_sponsor

    @api.one
    @api.depends('date_of_birth', 'birthyear')
    def _calc_age(self):
        if not self.sponsored_child:
            self.probable_age = None
            return

        now = datetime.date.today().year
        if self.date_of_birth:
            dob_year =  datetime.datetime.strptime(self.date_of_birth,'%Y-%m-%d').year
            self.probable_age = now - dob_year
        elif self.birthyear:
            self.probable_age = now - self.birthyear
        else:
            raise Warning(_('Either birthdate or birth year must be set.'))

    @api.one
    @api.depends('previous_images')
    def _get_number_of_images(self):
        number = 0
        if self.image:
            number += 1

        if not self.previous_images:
            self.number_of_images = number
        else:
            self.number_of_images = number + len(self.previous_images)

    def included_visits(self, all_visits):
        return filter(lambda visit: visit.include_in_letter, all_visits)

    def sponsor_names(self):
        retval = []
        for sponsorship in self.sponsors:
            if sponsorship.sub_sponsor_id:
                retval.append(sponsorship.sub_sponsor_id.name)
            else:
                retval.append(sponsorship.sponsor_id.name)
        return retval

    @api.one
    def _get_address(self):
        self.child_address = self.village.child_address

    @api.one
    def _calc_report_filename(self):
        self.report_index = self.report_index + 1
        self.report_filename = 'sponsorship-%s-2014-%d' % (self.child_ident, self.report_index)

    @api.one
    def _calc_visible_images(self):
        self.visible_image_ids = self.image_ids
        rv = []
        for image in self.image_ids:
            if not image.visible:
                continue
            rv.append(image.id)
        self.visible_image_ids = rv

    @api.multi
    @api.depends('last_schoolclass_update')
    def _calc_schoolclass_update_year(self):
        for child in self:
            if child.last_schoolclass_update:
                los_datos = fields.Date.from_string(child.last_schoolclass_update)
{'fraction_non_alphanumeric': 0.08465440710209259, 'fraction_numerical': 0.0025364616360177552, 'mean_word_length': 2.205792682926829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4848958', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1877, 'n_words': 414}