# -*- encoding: utf-8 -*- 
##############################################################################
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id: mrp.py 1292 2005-09-08 03:26:33Z pinky $
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

from osv import fields
from osv import osv


class res_partner(osv.osv):

	_inherit = 'res.partner'
	_name = "res.partner"
	
	_columns = {'partner_user_id' : fields.many2one('res.users', 'Related User'),}
  	
	def onchange_partner_category (self, cr, uid, ids, partner_user_id, lang, category_id) :
	
		# On verifie s'il y a changement de user pour le partenaire que le partenaire est bien professionnel
		# par contre on accepte que des professionnels n'aient pas encore de compte 

		warning = {} 
		valid = False
		print category_id
		
		# il y a la categorie Professionnels ? Ces categories sont celles du formulaire. On va chercher le nom dans la base de donnees
		
		for category in category_id[0][2]:
			print category,
			nom = self.pool.get('res.partner.category').browse(cr,uid,category).name
			print nom
			if nom == "Professionnels":
				valid = True
		print valid
						    
		# si le compte du partenaire est present et qu'il n'y a pas de categorie clients/professionnels
		if (partner_user_id): 
			if (valid == False): 
				# on affiche une message box
				warning = {
					'title': 'Attention !',
					'message': 'Les comptes sont pour les clients professionnels !'
					}
            	return {'warning': warning}
		
res_partner()

