2
#-*- encoding:utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
8
# Developer: Olivier DOSSMANN
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU Affero General Public License as
12
# published by the Free Software Foundation, either version 3 of the
13
# License, or (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU Affero General Public License for more details.
20
# You should have received a copy of the GNU Affero General Public License
21
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
##############################################################################
26
from tools.translate import _
28
class sale_order(osv.osv):
30
_inherit = 'sale.order'
32
def onchange_order_type(self, cr, uid, id, order_type=None, partner_id=None, context=None):
38
msg = _('Partner type is not compatible with given Order Type!')
39
if order_type in ['regular', 'donation_st', 'loan']:
40
# Check that partner correspond
42
partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
43
if partner and partner.partner_type not in ['internal', 'intermission', 'section', 'external']:
44
return {'warning': {'title': _('Error'), 'message': msg}}
45
elif order_type in ['donation_exp']:
46
# Check that partner correspond
48
partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
49
if partner and partner.partner_type not in ['internal', 'intermission', 'section']:
50
return {'warning': {'title': _('Error'), 'message': msg}}
55
if partner_id and order_type:
56
res.update({'value': {'order_policy': 'picking'}})
57
partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
58
if order_type != 'regular' or (order_type == 'regular' and partner.partner_type == 'internal'):
59
res.update({'value': {'order_policy': 'manual'}})
63
def _check_order_type_and_partner(self, cr, uid, ids, context=None):
65
Check that partner and order type are compatibles
68
'regular': ['internal', 'intermission', 'section', 'external'],
69
'donation_st': ['internal', 'intermission', 'section', 'external'],
70
'loan': ['internal', 'intermission', 'section', 'external'],
71
'donation_exp': ['internal', 'intermission', 'section'],
72
'in_kind': ['internal', 'intermission', 'section', 'external', 'esc'],
73
'direct': ['internal', 'intermission', 'section', 'external', 'esc'],
76
for so in self.browse(cr, uid, ids):
77
if so.order_type not in compats or so.partner_id.partner_type not in compats[so.order_type]:
82
(_check_order_type_and_partner, "Partner type and order type are incompatible! Please change either order type or partner.", ['order_type', 'partner_id']),
87
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: