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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 TeMPO Consulting, MSF
#
# 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 msf_partner import PARTNER_TYPE
import time
from tools.translate import _
from lxml import etree
class res_partner(osv.osv):
_name = 'res.partner'
_inherit = 'res.partner'
def search_in_product(self, cr, uid, obj, name, args, context=None):
'''
Search function of related field 'in_product'
'''
if not len(args):
return []
if context is None:
context = {}
if not context.get('product_id', False) or 'choose_supplier' not in context:
return []
supinfo_obj = self.pool.get('product.supplierinfo')
sup_obj = self.pool.get('res.partner')
res = []
info_ids = supinfo_obj.search(cr, uid, [('product_product_ids', '=', context.get('product_id'))])
info = supinfo_obj.read(cr, uid, info_ids, ['name'])
sup_in = [x['name'] for x in info]
for arg in args:
if arg[1] == '=':
if arg[2]:
res = sup_in
else:
res = sup_obj.search(cr, uid, [('id', 'not in', sup_in)])
if not res:
return [('id', '=', 0)]
return [('id', 'in', [x[0] for x in res])]
def _set_in_product(self, cr, uid, ids, field_name, arg, context=None):
'''
Returns according to the context if the partner is in product form
'''
if context is None:
context = {}
res = {}
product_obj = self.pool.get('product.product')
# If we aren't in the context of choose supplier on procurement list
if not context.get('product_id', False) or 'choose_supplier' not in context:
for i in ids:
res[i] = {'in_product': False, 'min_qty': 'N/A', 'delay': 'N/A'}
else:
product = product_obj.browse(cr, uid, context.get('product_id'))
seller_ids = []
seller_info = {}
# Get all suppliers defined on product form
for s in product.seller_ids:
seller_ids.append(s.name.id)
seller_info.update({s.name.id: {'min_qty': s.min_qty, 'delay': s.delay}})
# Check if the partner is in product form
for i in ids:
if i in seller_ids:
res[i] = {'in_product': True, 'min_qty': '%s' %seller_info[i]['min_qty'], 'delay': '%s' %seller_info[i]['delay']}
else:
res[i] = {'in_product': False, 'min_qty': 'N/A', 'delay': 'N/A'}
return res
def _get_price_info(self, cr, uid, ids, fiedl_name, args, context=None):
'''
Returns information from product supplierinfo if product_id is in context
'''
if not context:
context = {}
partner_price = self.pool.get('pricelist.partnerinfo')
res = {}
for id in ids:
res[id] = {'price_currency': False,
'price_unit': 0.00,
'valide_until_date': False}
if context.get('product_id'):
for partner in self.browse(cr, uid, ids, context=context):
product = self.pool.get('product.product').browse(cr, uid, context.get('product_id'), context=context)
uom = context.get('uom', product.uom_id.id)
pricelist = partner.property_product_pricelist_purchase
context.update({'uom': uom})
price_list = self.pool.get('product.product')._get_partner_info_price(cr, uid, product, partner.id, context.get('product_qty', 1.00), pricelist.currency_id.id, time.strftime('%Y-%m-%d'), uom, context=context)
if not price_list:
func_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
price = self.pool.get('res.currency').compute(cr, uid, func_currency_id, pricelist.currency_id.id, product.standard_price, round=False, context=context)
res[partner.id] = {'price_currency': pricelist.currency_id.id,
'price_unit': price,
'valide_until_date': False}
else:
info_price = partner_price.browse(cr, uid, price_list[0], context=context)
partner_currency_id = pricelist.currency_id.id
price = self.pool.get('res.currency').compute(cr, uid, info_price.currency_id.id, partner_currency_id, info_price.price, round=False, context=context)
currency = partner_currency_id
# Uncomment the following 2 lines if you want the price in currency of the pricelist.partnerinfo instead of partner default currency
# currency = info_price.currency_id.id
# price = info_price.price
res[partner.id] = {'price_currency': currency,
'price_unit': price,
'valide_until_date': info_price.valid_till}
return res
## QT : Remove _get_price_unit
## QT : Remove _get_valide_until_date
def _get_vat_ok(self, cr, uid, ids, field_name, args, context=None):
'''
Return True if the system configuration VA management is set to True
'''
vat_ok = self.pool.get('unifield.setup.configuration').get_config(cr, uid,).vat_ok
res = {}
for id in ids:
res[id] = vat_ok
return res
_columns = {
'manufacturer': fields.boolean(string='Manufacturer', help='Check this box if the partner is a manufacturer'),
'partner_type': fields.selection(PARTNER_TYPE, string='Partner type', required=True),
'in_product': fields.function(_set_in_product, fnct_search=search_in_product, string='In product', type="boolean", readonly=True, method=True, multi='in_product'),
'min_qty': fields.function(_set_in_product, string='Min. Qty', type='char', readonly=True, method=True, multi='in_product'),
'delay': fields.function(_set_in_product, string='Delivery Lead time', type='char', readonly=True, method=True, multi='in_product'),
'property_product_pricelist_purchase': fields.property(
'product.pricelist',
type='many2one',
relation='product.pricelist',
domain=[('type','=','purchase')],
string="Purchase default currency",
method=True,
view_load=True,
required=True,
help="This currency will be used, instead of the default one, for purchases from the current partner"),
'property_product_pricelist': fields.property(
'product.pricelist',
type='many2one',
relation='product.pricelist',
domain=[('type','=','sale')],
string="Field orders default currency",
method=True,
view_load=True,
required=True,
help="This currency will be used, instead of the default one, for field orders to the current partner"),
'price_unit': fields.function(_get_price_info, method=True, type='float', string='Unit price', multi='info'),
'valide_until_date' : fields.function(_get_price_info, method=True, type='char', string='Valid until date', multi='info'),
'price_currency': fields.function(_get_price_info, method=True, type='many2one', relation='res.currency', string='Currency', multi='info'),
'vat_ok': fields.function(_get_vat_ok, method=True, type='boolean', string='VAT OK', store=False, readonly=True),
}
_defaults = {
'manufacturer': lambda *a: False,
'partner_type': lambda *a: 'external',
'vat_ok': lambda obj, cr, uid, c: obj.pool.get('unifield.setup.configuration').get_config(cr, uid).vat_ok,
}
def _check_main_partner(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
bro_uid = self.pool.get('res.users').browse(cr,uid,uid)
bro = bro_uid.company_id
res = bro and bro.partner_id and bro.partner_id.id
cur = bro and bro.currency_id and bro.currency_id.id
po_def_cur = self.pool.get('product.pricelist').browse(cr,uid,vals.get('property_product_pricelist_purchase'))
fo_def_cur = self.pool.get('product.pricelist').browse(cr,uid,vals.get('property_product_pricelist'))
if res in ids:
for obj in self.browse(cr, uid, [res], context=context):
if context.get('from_setup') and bro.second_time and po_def_cur and po_def_cur.currency_id and po_def_cur.currency_id.id != cur:
raise osv.except_osv(_('Warning !'), _('You can not change the Purchase Default Currency of this partner anymore'))
if not context.get('from_setup') and po_def_cur and po_def_cur.currency_id and po_def_cur.currency_id.id != cur:
raise osv.except_osv(_('Warning !'), _('You can not change the Purchase Default Currency of this partner'))
if context.get('from_setup') and bro.second_time and fo_def_cur and fo_def_cur.currency_id and fo_def_cur.currency_id.id != cur:
raise osv.except_osv(_('Warning !'), _('You can not change the Field Orders Default Currency of this partner anymore'))
if not context.get('from_setup') and fo_def_cur and fo_def_cur.currency_id and fo_def_cur.currency_id.id != cur:
raise osv.except_osv(_('Warning !'), _('You can not change the Field Orders Default Currency of this partner'))
if obj.customer:
raise osv.except_osv(_('Warning !'), _('This partner can not be checked as customer'))
if obj.supplier:
raise osv.except_osv(_('Warning !'), _('This partner can not be checked as supplier'))
return True
_constraints = [
]
def get_objects_for_partner(self, cr, uid, ids, context):
"""
According to partner's ids:
return the most important objects linked to him that are not closed or opened
"""
# some verifications
if isinstance(ids, (int, long)):
ids = [ids]
if context is None:
context = {}
#objects
purchase_obj = self.pool.get('purchase.order')
sale_obj = self.pool.get('sale.order')
account_invoice_obj = self.pool.get('account.invoice') # for Supplier invoice/ Debit Note
pick_obj = self.pool.get('stock.picking') # for PICK/ PACK/ PPL/ INCOMING SHIPMENT/ DELIVERY
tender_obj = self.pool.get('tender')
com_vouch_obj = self.pool.get('account.commitment')# for commitment voucher
ship_obj = self.pool.get('shipment')
absl_obj = self.pool.get('account.bank.statement.line') # for register lines
aml_obj = self.pool.get('account.move.line')
# ids list (the domain are the same as the one used for the action window of the menus)
purchase_ids = purchase_obj.search(cr, uid,
[('rfq_ok', '=', False), ('partner_id', '=', ids[0]), ('state', 'not in', ['done', 'cancel'])],
context=context.update({'purchase_order': True}))
rfq_ids = purchase_obj.search(cr, uid,
[('rfq_ok', '=', True), ('partner_id', '=', ids[0]), ('state', 'not in', ['done', 'cancel'])],
context=context.update({'request_for_quotation': True}))
sale_ids = sale_obj.search(cr, uid,
[('procurement_request', '=', False), ('partner_id', '=', ids[0]), ('state', 'not in', ['done', 'cancel'])],
context=context)
intermission_vouch_in_ids = account_invoice_obj.search(cr, uid, [
('type','=','in_invoice'), ('is_debit_note', '=', False), ('is_inkind_donation', '=', False),
('is_intermission', '=', True), ('partner_id', '=', ids[0]), ('state', 'in', ['draft'])
], context = context.update({'type':'in_invoice', 'journal_type': 'intermission'}))
intermission_vouch_out_ids = account_invoice_obj.search(cr, uid, [
('type','=','out_invoice'), ('is_debit_note', '=', False), ('is_inkind_donation', '=', False),
('is_intermission', '=', True), ('partner_id', '=', ids[0]), ('state', 'in', ['draft'])
], context = context.update({'type':'out_invoice', 'journal_type': 'intermission'}))
donation_ids = account_invoice_obj.search(cr, uid, [
('type','=','in_invoice'), ('is_debit_note', '=', False), ('is_inkind_donation', '=', True),
('partner_id', '=', ids[0]), ('state', 'in', ['draft'])
], context = context.update({'type':'in_invoice', 'journal_type': 'inkind'}))
supp_invoice_ids = account_invoice_obj.search(cr, uid, [
('type','=','in_invoice'), ('register_line_ids', '=', False), ('is_inkind_donation', '=', False),
('is_intermission', '=', False), ('is_debit_note', "=", False), ('partner_id', '=', ids[0]), ('state', 'in', ['draft'])
], context = context.update({'type':'in_invoice', 'journal_type': 'purchase'}))
cust_refunds_ids = account_invoice_obj.search(cr, uid,
[('type','=','out_refund'), ('partner_id', '=', ids[0]), ('state', 'in', ['draft'])],
context = context.update({'type':'out_refund', 'journal_type': 'sale_refund'}))
debit_note_ids = account_invoice_obj.search(cr, uid, [
('type','=','out_invoice'), ('is_debit_note', '!=', False), ('is_inkind_donation', '=', False),
('partner_id', '=', ids[0]), ('state', 'in', ['draft'])
], context = context.update({'type':'out_invoice', 'journal_type': 'sale', 'is_debit_note': True}))
stock_transfer_vouch_ids = account_invoice_obj.search(cr, uid, [
('type','=','out_invoice'), ('is_debit_note', '=', False), ('is_inkind_donation', '=', False),
('is_intermission', '=', False), ('partner_id', '=', ids[0]), ('state', 'in', ['draft'])
], context = context.update({'type':'out_invoice', 'journal_type': 'sale'}))
incoming_ship_ids = pick_obj.search(cr, uid, [
('state', 'not in', ['done', 'cancel']), ('type', '=', 'in'), ('subtype', '=', 'standard'),
'|', ('partner_id', '=', ids[0]), ('partner_id2', '=', ids[0])
], context = context.update({
'contact_display': 'partner_address', 'subtype': 'in', 'picking_type': 'incoming_shipment', 'search_default_available':1
}))
out_ids = pick_obj.search(cr, uid, [
('state', 'not in', ['done', 'cancel']), ('type', '=', 'out'), ('subtype', '=', 'standard'),
'|', ('partner_id', '=', ids[0]), ('partner_id2', '=', ids[0])
], context = context.update({
'contact_display': 'partner_address', 'search_default_available': 1,'picking_type': 'delivery_order', 'subtype': 'standard'
}))
pick_ids = pick_obj.search(cr, uid, [
('state', 'not in', ['done', 'cancel']), ('type', '=', 'out'), ('subtype', '=', 'picking'),
'|', ('partner_id', '=', ids[0]), ('partner_id2', '=', ids[0])
], context = context.update({
'picking_screen':True, 'picking_type': 'picking_ticket', 'test':True, 'search_default_not_empty':1
}))
ppl_ids = pick_obj.search(cr, uid, [
('state', 'not in', ['done', 'cancel']), ('type', '=', 'out'), ('subtype', '=', 'ppl'),
'|', ('partner_id', '=', ids[0]), ('partner_id2', '=', ids[0])
], context=context.update({
'contact_display': 'partner_address', 'ppl_screen':True, 'picking_type': 'picking_ticket', 'search_default_available':1
}))
tender_ids = [tend for tend in tender_obj.search(cr, uid, [('state', '=', 'comparison')]) if ids[0] in tender_obj.read(cr, uid, tend, ['supplier_ids'])['supplier_ids']]
com_vouch_ids = com_vouch_obj.search(cr, uid, [('partner_id', '=', ids[0]), ('state', '!=', 'done')], context=context)
ship_ids = ship_obj.search(cr, uid,
[('state', 'not in', ['done', 'delivered']), '|', ('partner_id', '=', ids[0]), ('partner_id2', '=', ids[0])],
context=context)
absl_ids = absl_obj.search(cr, uid, [('state', 'in', ['draft', 'temp']), ('partner_id', '=', ids[0])], context=context)
aml_ids = aml_obj.search(cr, uid, [('partner_id', '=', ids[0]), ('reconcile_id', '=', False), ('account_id.reconcile', '=', True)])
return ', '.join([
po['name']+_(' (Purchase)') for po in purchase_obj.read(cr, uid, purchase_ids, ['name'], context) if po['name']]
+[rfq['name']+_(' (RfQ)') for rfq in purchase_obj.read(cr, uid, rfq_ids, ['name'], context) if rfq['name']]
+[so['name']+_(' (Field Order)') for so in sale_obj.read(cr, uid, sale_ids, ['name'], context) if so['name']]
+(intermission_vouch_in_ids and [_('%s Intermission Voucher IN') % (len(intermission_vouch_in_ids),)] or [])
+(intermission_vouch_out_ids and [_('%s Intermission Voucher OUT') % (len(intermission_vouch_out_ids),)] or [])
+(donation_ids and [_('%s Donation(s)') % (len(donation_ids),)] or [])
+(supp_invoice_ids and [_('%s Supplier Invoice(s)') % (len(supp_invoice_ids), )] or [])
+(cust_refunds_ids and [_('%s Customer Refund(s)') % (len(cust_refunds_ids), )] or [])
+(debit_note_ids and [_('%s Debit Note(s)') % (len(debit_note_ids), )] or [])
+(stock_transfer_vouch_ids and [_('%s Stock Transfer Voucher(s)') % (len(stock_transfer_vouch_ids),)] or [])
+[inc_ship['name']+_(' (Incoming Shipment)') for inc_ship in pick_obj.read(cr, uid, incoming_ship_ids, ['name'], context) if inc_ship['name']]
+[out['name']+_(' (OUT)') for out in pick_obj.read(cr, uid, out_ids, ['name'], context) if out['name']]
+[pick['name']+_(' (PICK)') for pick in pick_obj.read(cr, uid, pick_ids, ['name'], context) if pick['name']]
+[ppl['name']+_(' (PPL)') for ppl in pick_obj.read(cr, uid, ppl_ids, ['name'], context) if ppl['name']]
+[tend['name']+_(' (Tender)') for tend in tender_obj.read(cr, uid, tender_ids, ['name'], context) if tend['name']]
+[com_vouch['name']+_(' (Commitment Voucher)') for com_vouch in com_vouch_obj.read(cr, uid, com_vouch_ids, ['name'], context) if com_vouch['name']]
+[ship['name']+_(' (Shipment)') for ship in ship_obj.read(cr, uid, ship_ids, ['name'], context) if ship['name']]
+[absl.name + '(' + absl.statement_id.name + _(' Register)') for absl in absl_obj.browse(cr, uid, absl_ids, context) if absl.name and absl.statement_id and absl.statement_id.name]
+[_('%s (Journal Item)') % (aml['move_id'] and aml['move_id'][1] or '') for aml in aml_obj.read(cr, uid, aml_ids, ['move_id'])]
)
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
if not context:
context = {}
self._check_main_partner(cr, uid, ids, vals, context=context)
bro_uid = self.pool.get('res.users').browse(cr,uid,uid)
bro = bro_uid.company_id
res = bro and bro.partner_id and bro.partner_id.id
# Avoid the modification of the main partner linked to the company
if not context.get('from_config') and res and res in ids:
for field in ['name', 'partner_type', 'customer', 'supplier']:
if field in vals:
del vals[field]
# [utp-315] avoid deactivating partner that have still open document linked to them
if 'active' in vals and vals.get('active') == False:
objects_linked_to_partner = self.get_objects_for_partner(cr, uid, ids, context)
if objects_linked_to_partner:
raise osv.except_osv(_('Warning'),
_("""The following documents linked to the partner need to be closed before deactivating the partner: %s"""
) % (objects_linked_to_partner))
return super(res_partner, self).write(cr, uid, ids, vals, context=context)
def create(self, cr, uid, vals, context=None):
if 'partner_type' in vals and vals['partner_type'] in ('internal', 'section', 'esc', 'intermission'):
msf_customer = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_internal_customers')
msf_supplier = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_internal_suppliers')
if msf_customer and not 'property_stock_customer' in vals:
vals['property_stock_customer'] = msf_customer[1]
if msf_supplier and not 'property_stock_supplier' in vals:
vals['property_stock_supplier'] = msf_supplier[1]
return super(res_partner, self).create(cr, uid, vals, context=context)
def copy_data(self, cr, uid, id, default=None, context=None):
'''
Erase some unused data copied from the original object, which sometime could become dangerous, as in UF-1631/1632,
when duplicating a new partner (by button duplicate), or company, it creates duplicated currencies
'''
if default is None:
default = {}
if context is None:
context = {}
fields_to_reset = ['ref_companies'] # reset this value, otherwise the content of the field triggers the creation of a new company
to_del = []
for ftr in fields_to_reset:
if ftr not in default:
to_del.append(ftr)
res = super(res_partner, self).copy_data(cr, uid, id, default=default, context=context)
for ftd in to_del:
if ftd in res:
del(res[ftd])
return res
def on_change_active(self, cr, uid, ids, active, context=None):
"""
[utp-315] avoid deactivating partner that have still open document linked to them.
"""
if not active:
# some verifications
if isinstance(ids, (int, long)):
ids = [ids]
if context is None:
context = {}
objects_linked_to_partner = self.get_objects_for_partner(cr, uid, ids, context)
if objects_linked_to_partner:
return {'value': {'active': True},
'warning': {'title': _('Error'),
'message': _("Some documents linked to this partner need to be closed or cancelled before deactivating the partner: %s"
) % (objects_linked_to_partner,)}}
return {}
def on_change_partner_type(self, cr, uid, ids, partner_type, sale_pricelist, purchase_pricelist):
'''
Change the procurement method according to the partner type
'''
price_obj = self.pool.get('product.pricelist')
cur_obj = self.pool.get('res.currency')
user_obj = self.pool.get('res.users')
r = {'po_by_project': 'project'}
if not partner_type or partner_type in ('external', 'internal'):
r.update({'po_by_project': 'all'})
sale_authorized_price = price_obj.search(cr, uid, [('type', '=', 'sale'), ('in_search', '=', partner_type)])
if sale_authorized_price and sale_pricelist not in sale_authorized_price:
r.update({'property_product_pricelist': sale_authorized_price[0]})
purchase_authorized_price = price_obj.search(cr, uid, [('type', '=', 'purchase'), ('in_search', '=', partner_type)])
if purchase_authorized_price and purchase_pricelist not in purchase_authorized_price:
r.update({'property_product_pricelist_purchase': purchase_authorized_price[0]})
if partner_type and partner_type in ('internal', 'section', 'esc', 'intermission'):
msf_customer = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_internal_customers')
if msf_customer:
r.update({'property_stock_customer': msf_customer[1]})
msf_supplier = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_internal_suppliers')
if msf_supplier:
r.update({'property_stock_supplier': msf_supplier[1]})
else:
other_customer = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_customers')
if other_customer:
r.update({'property_stock_customer': other_customer[1]})
other_supplier = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_suppliers')
if other_supplier:
r.update({'property_stock_supplier': other_supplier[1]})
if partner_type and partner_type == 'esc':
r['zone'] = 'international'
return {'value': r}
def search(self, cr, uid, args=None, offset=0, limit=None, order=None, context=None, count=False):
'''
Sort suppliers to have all suppliers in product form at the top of the list
'''
supinfo_obj = self.pool.get('product.supplierinfo')
if context is None:
context = {}
if args is None:
args = []
# Get all supplier
tmp_res = super(res_partner, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
if not context.get('product_id', False) or 'choose_supplier' not in context or count:
return tmp_res
else:
# Get all supplier in product form
args.append(('in_product', '=', True))
res_in_prod = super(res_partner, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
new_res = []
# Sort suppliers by sequence in product form
if 'product_id' in context:
supinfo_ids = supinfo_obj.search(cr, uid, [('name', 'in', res_in_prod), ('product_product_ids', '=', context.get('product_id'))], order='sequence')
for result in supinfo_obj.read(cr, uid, supinfo_ids, ['name']):
try:
tmp_res.remove(result['name'][0])
new_res.append(result['name'][0])
except:
pass
#return new_res # comment this line to have all suppliers (with suppliers in product form at the top of the list)
new_res.extend(tmp_res)
return new_res
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
"""
Show the button "Show inactive" in the partner search view only when we have in the context {'show_button_show_inactive':1}.
"""
if not context:
context = {}
view = super(res_partner, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
if view_type == 'search':
if not context or not context.get('show_button_show_inactive', False):
tree = etree.fromstring(view['arch'])
fields = tree.xpath('//filter[@name="inactive"]')
for field in fields:
field.set('invisible', "1")
view['arch'] = etree.tostring(tree)
return view
res_partner()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|