Skip to content

Commit

Permalink
Merge pull request #232 from CompassionCH/master
Browse files Browse the repository at this point in the history
CO-793 Warn for special sponsor categories
  • Loading branch information
ecino authored Apr 4, 2017
2 parents 479c01c + ac39157 commit 0821797
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions sponsorship_switzerland/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@

from . import contracts
from . import account_invoice
from . import res_partner_category
17 changes: 16 additions & 1 deletion sponsorship_switzerland/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
##############################################################################

import logging
from openerp import api, models, fields
from openerp import api, models, fields, _

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -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 #
##########################################################################
Expand Down
21 changes: 21 additions & 0 deletions sponsorship_switzerland/models/res_partner_category.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
#
# 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()
11 changes: 11 additions & 0 deletions sponsorship_switzerland/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@
</button>
</field>
</record>

<record id="view_partner_category_form" model="ir.ui.view">
<field name="name">Partner Tags</field>
<field name="model">res.partner.category</field>
<field name="inherit_id" ref="base.view_partner_category_form"/>
<field name="arch" type="xml">
<field name="active" position="after">
<field name="warn_sponsorship"/>
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 0821797

Please sign in to comment.