1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2014 TeMPO Consulting, MSF
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import fields
25
from tools.translate import _
28
class res_partner(osv.osv):
30
Override the res_partner class to add some feature
31
from Order Sourcing Tool
34
_inherit = 'res.partner'
36
def _get_available_for_dpo(self, cr, uid, ids, field_name, args, context=None):
38
Return for each partner if he's available for DPO selection
41
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.partner_id.id
43
for partner in self.browse(cr, uid, ids, context=context):
44
res[partner.id] = False
45
if partner.supplier and partner.id != company_id and partner.partner_type in ('external', 'esc'):
46
res[partner.id] = True
50
def _src_available_for_dpo(self, cr, uid, obj, name, args, context=None):
52
Returns all partners according to args
56
if len(arg) > 2 and arg[0] == 'available_for_dpo':
58
raise osv.except_osv(_('Error'), _('Bad operator'))
60
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.partner_id.id
61
res.append(('id', '!=', company_id))
62
res.append(('partner_type', 'in', ('external', 'esc')))
63
res.append(('supplier', '=', True))
67
def _get_fake(self, cr, uid, ids, fields, arg, context=None):
68
if isinstance(ids, (int, long)):
75
def _check_partner_type(self, cr, uid, obj, name, args, context=None):
78
active_id = context.get('active_id', False)
79
if isinstance(active_id, (int, long)):
80
active_id = [active_id]
85
if arg[0] == 'check_partner':
86
if arg[1] != '=' or not isinstance(arg[2], (int, long)):
87
raise osv.except_osv(_('Error'), _('Filter check_partner different than (arg[0], =, id) not implemented.'))
89
so = self.pool.get('sale.order').browse(cr, uid, arg[2])
90
sl = self.pool.get('sale.order.line').browse(cr, uid, active_id)[0]
91
if not so.procurement_request:
92
newargs.append(('partner_type', 'in', ['external', 'esc']))
93
elif so.procurement_request and not sl.product_id:
94
newargs.append(('partner_type', 'in', ['internal', 'section', 'intermission']))
99
def _check_partner_type_rfq(self, cr, uid, obj, name, args, context=None):
104
if arg[0] == 'check_partner_rfq':
105
if arg[1] != '=' or not isinstance(arg[2], (int, long)):
106
raise osv.except_osv(_('Error'), _('Filter check_partner_rfq different than (arg[0], =, id) not implemented.'))
108
tender = self.pool.get('tender').browse(cr, uid, arg[2])
109
if tender.sale_order_id:
110
newargs.append(('partner_type', 'in', ['external', 'esc']))
115
def _check_partner_type_ir(self, cr, uid, obj, name, args, context=None):
118
active_ids = context.get('active_ids', False)
119
if isinstance(active_ids, (int, long)):
120
active_ids = [active_ids]
125
if arg[0] == 'check_partner_ir':
127
raise osv.except_osv(_('Error'), _('Filter check_partner_ir different than (arg[0], =, id) not implemented.'))
130
sol = self.pool.get('sale.order.line').browse(cr, uid, active_ids)[0]
131
if not context.get('product_id', False) and sol.order_id.procurement_request:
132
newargs.append(('partner_type', 'in', ['internal', 'section', 'intermission']))
137
def _check_partner_type_po(self, cr, uid, obj, name, args, context=None):
139
Create a domain on the field partner_id on the view id="purchase_move_buttons"
148
if arg[0] == 'check_partner_po':
150
or arg[2]['order_type'] not in ['regular', 'donation_exp', 'donation_st', 'loan', 'in_kind', 'purchase_list', 'direct']\
151
or not isinstance(arg[2]['partner_id'], (int, long)):
152
raise osv.except_osv(_('Error'), _('Filter check_partner_po different than (arg[0], =, %s) not implemented.') % arg[2])
153
order_type = arg[2]['order_type']
154
# Added by UF-1660 to filter partners
155
# do nothing on partner_type for loan
157
if order_type == 'loan':
158
p_list = ['internal', 'intermission', 'section', 'external']
159
elif order_type in ['direct', 'in_kind']:
160
p_list = ['esc', 'external']
161
elif order_type in ['donation_st', 'donation_exp']:
162
p_list = ['internal', 'intermission', 'section']
163
elif order_type in ['purchase_list']:
164
p_list = ['external']
165
# show all supplier for non taken cases
169
newargs.append(('partner_type', 'in', p_list))
174
def _src_contains_fo(self, cr, uid, obj, name, args, context=None):
177
if arg[0] == 'line_contains_fo':
178
if type(arg[2]) == type(list()):
179
for line in self.pool.get('sale.order.line').browse(cr, uid, arg[2][0][2], context=context):
180
if not line.order_id.procurement_request:
181
res.append(('partner_type', 'in', ['external', 'esc']))
186
'available_for_dpo': fields.function(_get_available_for_dpo, fnct_search=_src_available_for_dpo,
187
method=True, type='boolean', string='Available for DPO', store=False),
188
'check_partner': fields.function(_get_fake, method=True, type='boolean', string='Check Partner Type', fnct_search=_check_partner_type),
189
'check_partner_rfq': fields.function(_get_fake, method=True, type='boolean', string='Check Partner Type', fnct_search=_check_partner_type_rfq),
190
'check_partner_ir': fields.function(_get_fake, method=True, type='boolean', string='Check Partner Type On IR', fnct_search=_check_partner_type_ir),
191
'check_partner_po': fields.function(_get_fake, method=True, type='boolean', string='Check Partner Type On PO', fnct_search=_check_partner_type_po),
192
'line_contains_fo': fields.function(_get_fake, fnct_search=_src_contains_fo, method=True, string='Lines contains FO', type='boolean', store=False),
197
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: