diff --git a/sponsorship_switzerland/models/__init__.py b/sponsorship_switzerland/models/__init__.py index 8f4b8641f..6744cf284 100644 --- a/sponsorship_switzerland/models/__init__.py +++ b/sponsorship_switzerland/models/__init__.py @@ -11,3 +11,4 @@ from . import contracts from . import account_invoice +from . import res_partner_category diff --git a/sponsorship_switzerland/models/contracts.py b/sponsorship_switzerland/models/contracts.py index 1d4461101..d317d11c7 100644 --- a/sponsorship_switzerland/models/contracts.py +++ b/sponsorship_switzerland/models/contracts.py @@ -10,7 +10,7 @@ ############################################################################## import logging -from openerp import api, models, fields +from openerp import api, models, fields, _ logger = logging.getLogger(__name__) @@ -75,6 +75,21 @@ def reactivate_contract(self): super(RecurringContracts, self).reactivate_contract() self._auto_reconcile() + @api.onchange('child_id') + def onchange_child_id(self): + res = super(RecurringContracts, self).onchange_child_id() + warn_categories = self.correspondant_id.category_id.filtered( + 'warn_sponsorship') + if warn_categories: + cat_names = warn_categories.mapped('name') + return { + 'warning': { + 'title': _('The sponsor has special categories'), + 'message': ', '.join(cat_names) + } + } + return res + ########################################################################## # WORKFLOW METHODS # ########################################################################## diff --git a/sponsorship_switzerland/models/res_partner_category.py b/sponsorship_switzerland/models/res_partner_category.py new file mode 100644 index 000000000..7f7f36ba3 --- /dev/null +++ b/sponsorship_switzerland/models/res_partner_category.py @@ -0,0 +1,21 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2016 Compassion CH (http://www.compassion.ch) +# Releasing children from poverty in Jesus' name +# @author: Emanuel Cino +# +# The licence is in the file __openerp__.py +# +############################################################################## + +from openerp import models, fields + + +class ResPartnerCategory(models.Model): + """ + Warn user when making a sponsorship for sponsor that has a category. + """ + _inherit = 'res.partner.category' + + warn_sponsorship = fields.Boolean() diff --git a/sponsorship_switzerland/views/res_partner_view.xml b/sponsorship_switzerland/views/res_partner_view.xml index d9ec00f3b..49acf43f1 100644 --- a/sponsorship_switzerland/views/res_partner_view.xml +++ b/sponsorship_switzerland/views/res_partner_view.xml @@ -17,5 +17,16 @@ + + + Partner Tags + res.partner.category + + + + + + + \ No newline at end of file