1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 osv,fields
23 from tools.translate import _
27 class wiz_auc_lots_buyer_map(osv.osv_memory):
28 _name = 'auction.lots.buyer_map'
29 _description = 'Map Buyer'
31 'ach_login': fields.char('Buyer Username', size=64, required=True),
32 'ach_uid': fields.many2one('res.partner','Buyer', required=True),
35 def default_get(self, cr, uid, fields, context=None):
37 To get default values for the object.
38 @param self: The object pointer.
39 @param cr: A database cursor
40 @param uid: ID of the user currently logged in
41 @param fields: List of fields for which we want default values
42 @param context: A standard dictionary
43 @return: A dictionary which of fields with values.
47 res = super(wiz_auc_lots_buyer_map,self).default_get(cr, uid, fields, context=context)
48 auction_lots_obj = self.pool.get('auction.lots')
49 lots_ids = auction_lots_obj.search(cr, uid, [('ach_uid', '=', ''), ('ach_login', '!=', '')])
50 for rec in auction_lots_obj.browse(cr, uid, lots_ids, context=context):
51 if (not rec.ach_uid or not rec.ach_login):
52 res.update(self._start(cr, uid, context.get('active_ids', []), context=context))
54 res.update(self._start(cr, uid, context.get('active_ids', []), context=context))
57 def _start(self, cr, uid, ids, context=None):
59 Returns login if already there in the selected record.
60 @param self: The object pointer.
61 @param cr: A database cursor
62 @param uid: ID of the user currently logged in
63 @param ids: List of ids
64 @param context: A standard dictionary
65 @return: login field from current record.
67 lots_obj = self.pool.get('auction.lots')
68 for rec in lots_obj.browse(cr, uid, ids, context=context):
69 if (len(ids)==1) and (not rec.ach_uid and not rec.ach_login):
70 raise osv.except_osv(_('Error'), _('No buyer is set for this lot.'))
71 if not rec.ach_uid and rec.ach_login:
72 return {'ach_login': rec.ach_login}
75 def buyer_map_set(self, cr, uid, ids, context=None):
77 To map the buyer and login name.
78 @param self: The object pointer.
79 @param cr: A database cursor
80 @param uid: ID of the user currently logged in
81 @param ids: List of ids
82 @param context: A standard dictionary
86 rec_ids = context and context.get('active_ids',[]) or []
87 assert rec_ids, _('Active IDs not Found')
88 lots_obj = self.pool.get('auction.lots')
89 for current in self.browse(cr, uid, ids, context=context):
90 for lots in lots_obj.browse(cr, uid, rec_ids, context=context):
91 if lots.ach_login == current.ach_login:
92 lots_obj.write(cr, uid, [lots.id], {'ach_uid': current.ach_uid.id}, context=context)
93 return {'type': 'ir.actions.act_window_close'}
95 def fields_view_get(self, cr, uid, view_id=None, view_type='form',
96 context=None, toolbar=False, submenu=False):
98 Changes the view dynamically
99 @param self: The object pointer.
100 @param cr: A database cursor
101 @param uid: ID of the user currently logged in
102 @param context: A standard dictionary
103 @return: New arch of view.
107 record_ids = context and context.get('active_ids', []) or []
108 res = super(wiz_auc_lots_buyer_map, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
109 if context.get('active_model','') != 'auction.lots':
111 lots_obj = self.pool.get('auction.lots')
114 for lots in lots_obj.browse(cr, uid, record_ids, context=context):
117 <form title="Mapping Result">
118 <group col="2" colspan="4">
119 <label string="All objects are assigned to buyers !"/>
121 <separator string="" colspan="4"/>
122 <button icon='gtk-cancel' special="cancel"
131 wiz_auc_lots_buyer_map()
133 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: