<commit_before># -*- encoding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __openerp__.py
#
##############################################################################

from openerp.osv import orm, fields
from openerp.tools.translate import _


class contract_origin(orm.Model):

    """ Origin of a contract """
    _name = 'recurring.contract.origin'

    def _get_origin_types(self, cr, uid, context=None):
        return [
            ('partner', _("Contact with sponsor/ambassador")),
            ('event', _("Event")),
            ('marketing', _("Marketing campaign")),
            ('sub', _("SUB sponsorship")),
            ('transfer', _("Transfer")),
            ('already_sponsor', _("Is already sponsor")),
            ('other', _("Other")),
        ]

    def _define_name(self, cr, uid, ids, field_name, args, context=None):
        """ Returns a good name for related fields. """
        if not isinstance(ids, list):
            ids = [ids]
        return {origin.id: self._name_get(origin)
                for origin in self.browse(cr, uid, ids, context)}

    def _name_get(self, origin):
        name = ""
        if origin.type == 'partner':
            name = origin.partner_id.name
        elif origin.type in ('event', 'marketing'):
            name = origin.analytics_id.name
        elif origin.type == 'sub':
            if origin.contract_id:
                name = 'SUB Sponsorship - {0} ({1})'.format(
                    origin.contract_id.child_id.code,
                    origin.contract_id.end_date.strftime("%m/%Y"))
            else:
                name = 'SUB Sponsorship'
        elif origin.type == 'transfer':
            if origin.country_id:
                name = 'Transfer from ' + origin.country_id.name
            else:
                name = 'Transfer from partner country'
        elif origin.type == 'already_sponsor':
            name = 'Was already a sponsor'
        elif origin.type == 'other':
            name = origin.other_name or 'Other...'
        return name

    _columns = {
        'name': fields.function(_define_name, type="char", string=_("Name"),
                                store=True),
        'type': fields.selection(_get_origin_types, _("Type"), help=_(
            "Origin of contract : "
            " * Contact with sponsor/ambassador : an other sponsor told the "
            "person about Compassion."
            " * Event : sponsorship was made during an event"<commit_msg>Include date of previous sponsorship origin<commit_after># -*- encoding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __openerp__.py
#
##############################################################################

from openerp.osv import orm, fields
from openerp.tools.translate import _


class contract_origin(orm.Model):

    """ Origin of a contract """
    _name = 'recurring.contract.origin'

    def _get_origin_types(self, cr, uid, context=None):
        return [
            ('partner', _("Contact with sponsor/ambassador")),
            ('event', _("Event")),
            ('marketing', _("Marketing campaign")),
            ('sub', _("SUB sponsorship")),
            ('transfer', _("Transfer")),
            ('already_sponsor', _("Is already sponsor")),
            ('other', _("Other")),
        ]

    def _define_name(self, cr, uid, ids, field_name, args, context=None):
        """ Returns a good name for related fields. """
        if not isinstance(ids, list):
            ids = [ids]
        return {origin.id: self._name_get(origin)
                for origin in self.browse(cr, uid, ids, context)}

    def _name_get(self, origin):
        name = ""
        if origin.type == 'partner':
            name = origin.partner_id.name
        elif origin.type in ('event', 'marketing'):
            name = origin.analytics_id.name
        elif origin.type == 'sub':
            if origin.contract_id:
                name = 'SUB Sponsorship - {0} ({1})'.format(
                    origin.contract_id.child_id.code,
                    origin.contract_id.end_date)
            else:
                name = 'SUB Sponsorship'
        elif origin.type == 'transfer':
            if origin.country_id:
                name = 'Transfer from ' + origin.country_id.name
            else:
                name = 'Transfer from partner country'
        elif origin.type == 'already_sponsor':
            name = 'Was already a sponsor'
        elif origin.type == 'other':
            name = origin.other_name or 'Other...'
        return name

    _columns = {
        'name': fields.function(_define_name, type="char", string=_("Name"),
                                store=True),
        'type': fields.selection(_get_origin_types, _("Type"), help=_(
            "Origin of contract : "
            " * Contact with sponsor/ambassador : an other sponsor told the "
            "person about Compassion."
            " * Event : sponsorship was made during an event"
{'fraction_non_alphanumeric': 0.17878338278931752, 'fraction_numerical': 0.0025964391691394658, 'mean_word_length': 2.164906103286385, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4884566', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1406, 'n_words': 392}