# -*- encoding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2016 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: Emanuel Cino <ecino@compassion.ch>
#
#    The licence is in the file __openerp__.py
#
##############################################################################
import uuid
from openerp import api, fields, models


class ResPartner(models.Model):
    """ Add Partner UUID
    """

    _inherit = 'res.partner'

    uuid = fields.Char(compute='compute_uuid', store=True)
    pays_christmas_fund = fields.Boolean(
        compute='compute_pays_christmas_fund')

    _sql_constraints = [
        ('unique_uuid', 'unique(uuid)', 'Partner UUID must be unique!')
    ]

    @api.depends('ref')
    @api.multi
    def compute_uuid(self):
        for partner in self:
            partner.uuid = uuid.uuid4()

    @api.multi
    def compute_pays_christmas_fund(self):
        for partner in self:
            partner.pays_christmas_fund = False
            for contract_line in \
                    partner.other_contract_ids.contract_line_ids.with_context(
                        lang='en_US'):
                if contract_line.product_id.\
                        name_template == 'Christmas Gift Fund':
                    partner.pays_christmas_fund = True
                    break

    @api.model
    def update_partner_payment_terms(self):
        """ Function to call with ERPPEEK to update all partner payment
            terms based on their sponsorship payment preferences.
        """
        partners = self.search([('customer', '=', True)])
        for partner in partners:
            contract = self.env['recurring.contract'].search([
                ('partner_id', '=', partner.id),
                ('state', '=', 'active')
            ], limit=1)
            if contract:
                partner.property_payment_term = contract.payment_term_id
        return True

@@ -1039,98 +1039,15 @@
     
-partner.pays_christmas_fund = False%0A            for contract_line in %5C%0A                   
+lines =
  par
@@ -1074,26 +1074,8 @@
 ids.
-contract_line_ids.
 with
@@ -1100,24 +1100,16 @@
         
-        
 lang='en
@@ -1113,17 +1113,24 @@
 'en_US')
-:
+.mapped(
 %0A       
@@ -1130,35 +1130,33 @@
                 
-if 
+'
 contract_line.pr
@@ -1152,16 +1152,20 @@
 act_line
+_ids
 .product
@@ -1172,82 +1172,24 @@
 _id.
-%5C%0A                        name_template == 'Christmas Gift Fund':%0A        
+name_template')%0A
     
@@ -1230,38 +1230,38 @@
 d = 
-True%0A                    break
+'Christmas Gift Fund' in lines
 %0A%0A  

Fix bug in pays christmas computation