1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (C) 2011 MSF, TeMPO Consulting
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as
8
# published by the Free Software Foundation, either version 3 of the
9
# License, or (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
##############################################################################
22
from osv import fields
23
from tools.translate import _
25
class res_partner(osv.osv):
27
_inherit = 'res.partner'
29
def _get_fake(self, cr, uid, ids, fields, arg, context=None):
31
Fake method for 'check_partner_so' field.
33
if isinstance(ids, (int, long)):
40
def _check_partner_type_so(self, cr, uid, obj, name, args, context=None):
42
Create a domain on the field partner_id
49
partner_obj = self.pool.get('res.partner')
51
if arg[0] == 'check_partner_so':
53
or arg[2]['order_type'] not in ['regular', 'donation_exp', 'donation_st', 'loan', 'in_kind', 'purchase_list', 'direct']\
54
or not isinstance(arg[2]['partner_id'], (int, long)):
55
raise osv.except_osv(_('Error'), _('Filter check_partner_so different than (arg[0], =, %s) not implemented.') % arg[2])
56
partner_id = arg[2]['partner_id']
57
order_type = arg[2]['order_type']
59
if order_type in ['regular']:
60
p_list = ['internal', 'intermission', 'external'] # UTP-953: Cannot create an FO regular for Intersection due to the Push Flow sync
61
elif order_type in ['donation_st', 'loan', 'donation_exp']:
62
p_list = ['internal', 'intermission', 'section', 'external']
63
elif order_type in ['direct', 'in_kind']:
64
p_list = ['internal', 'intermission', 'section', 'esc', 'external']
65
# show all supplier for non taken cases
69
newargs.append(('partner_type', 'in', p_list))
74
def _search_partner_not_int(self, cr, uid, obj, name, args, context=None):
77
if not isinstance(arg[2], dict) or not arg[2].get('ids') or not arg[2].get('ids')[0]:
79
if arg[2]['type'] == 'po':
80
for po in self.pool.get('purchase.order').browse(cr, uid, arg[2]['ids'], context=context):
82
dom.append(('partner_type', 'not in', ['internal','section','intermission']))
84
for tender in self.pool.get('tender').browse(cr, uid, arg[2]['ids'], context=context):
85
if tender.tender_from_fo:
86
dom.append(('partner_type', 'not in', ['internal','section','intermission']))
90
'check_partner_so': fields.function(_get_fake, method=True, type='boolean', string='Check Partner Type On SO', fnct_search=_check_partner_type_so),
91
'partner_not_int': fields.function(_get_fake, method=True, type='boolean', string='Is PO/Tender from FO ?', fnct_search=_search_partner_not_int),
95
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: