1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2011 MSF, TeMPO Consulting
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv
from osv import fields
from tools.translate import _
class res_partner(osv.osv):
_name = 'res.partner'
_inherit = 'res.partner'
def _get_fake(self, cr, uid, ids, fields, arg, context=None):
"""
Fake method for 'check_partner_so' field.
"""
if isinstance(ids, (int, long)):
ids = [ids]
result = {}
for id in ids:
result[id] = False
return result
def _check_partner_type_so(self, cr, uid, obj, name, args, context=None):
"""
Create a domain on the field partner_id
"""
if context is None:
context = {}
if not args:
return []
newargs = []
partner_obj = self.pool.get('res.partner')
for arg in args:
if arg[0] == 'check_partner_so':
if arg[1] != '=' \
or arg[2]['order_type'] not in ['regular', 'donation_exp', 'donation_st', 'loan', 'in_kind', 'purchase_list', 'direct']\
or not isinstance(arg[2]['partner_id'], (int, long)):
raise osv.except_osv(_('Error'), _('Filter check_partner_so different than (arg[0], =, %s) not implemented.') % arg[2])
partner_id = arg[2]['partner_id']
order_type = arg[2]['order_type']
p_list = []
if order_type in ['regular']:
p_list = ['internal', 'intermission', 'external'] # UTP-953: Cannot create an FO regular for Intersection due to the Push Flow sync
elif order_type in ['donation_st', 'loan']:
p_list = ['internal', 'intermission', 'section', 'external']
elif order_type in ['direct', 'in_kind']:
p_list = ['internal', 'intermission', 'section', 'esc', 'external']
elif order_type in ['donation_exp']:
p_list = ['internal', 'intermission', 'section']
# show all supplier for non taken cases
else:
pass
if p_list:
newargs.append(('partner_type', 'in', p_list))
else:
newargs.append(args)
return newargs
def _search_partner_not_int(self, cr, uid, obj, name, args, context=None):
dom = []
for arg in args:
if not isinstance(arg[2], dict) or not arg[2].get('ids') or not arg[2].get('ids')[0]:
return dom
if arg[2]['type'] == 'po':
for po in self.pool.get('purchase.order').browse(cr, uid, arg[2]['ids'], context=context):
if po.po_from_fo:
dom.append(('partner_type', 'not in', ['internal','section','intermission']))
else:
for tender in self.pool.get('tender').browse(cr, uid, arg[2]['ids'], context=context):
if tender.tender_from_fo:
dom.append(('partner_type', 'not in', ['internal','section','intermission']))
return dom
_columns = {
'check_partner_so': fields.function(_get_fake, method=True, type='boolean', string='Check Partner Type On SO', fnct_search=_check_partner_type_so),
'partner_not_int': fields.function(_get_fake, method=True, type='boolean', string='Is PO/Tender from FO ?', fnct_search=_search_partner_not_int),
}
res_partner()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|