[ADD] auction: Added osv_memory wizard for 'Map buyer username to Partners'.

bzr revid: uco@tinyerp.co.in-20100323134503-gfumtlx8yui2pnd4
This commit is contained in:
uco (OpenERP) 2010-03-23 19:15:03 +05:30
parent b473ba6e15
commit 1d98e10bc2
5 changed files with 169 additions and 107 deletions

View File

@ -44,6 +44,8 @@
'wizard/auction_payer_sel_view.xml',
'wizard/auction_lots_sms_send_view.xml',
'wizard/auction_catalog_flagey_view.xml',
# 'wizard/auction_aie_send_result_view.xml',
'wizard/auction_lots_buyer_map_view.xml',
'auction_view.xml',
'auction_report.xml',

View File

@ -30,5 +30,8 @@ import auction_payer_sel
import auction_lots_sms_send
import auction_catalog_flagey_report
#import auction_aie_send_result
import auction_lots_buyer_map
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,128 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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/>.
#
##############################################################################
import netsvc
import sql_db
from osv import osv,fields
class wiz_auc_lots_buyer_map(osv.osv_memory):
_name = 'auction.lots.buyer_map'
_description = 'Map Buyer'
_columns = {
'ach_login': fields.char('Buyer Username', size=64, required=True),
'ach_uid': fields.many2one('res.partner','Buyer', required=True),
}
def default_get(self, cr, uid, fields, context):
"""
To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param fields: List of fields for which we want default values
@param context: A standard dictionary
@return: A dictionary which of fields with values.
"""
ids = context and context.get('active_ids',False) or False
assert ids, _('Active IDs not Found')
res = super(wiz_auc_lots_buyer_map,self).default_get(cr, uid, fields, context)
cr.execute('select id from auction_lots where (ach_uid is null and ach_login is not null) ')
v_ids = [x[0] for x in cr.fetchall()]
for rec in self.pool.get('auction.lots').browse(cr, uid, v_ids, context):
if (not rec.ach_uid or not rec.ach_login):
res.update(self._start(cr, uid, ids, context))
return res
res.update(self._start(cr, uid, ids, context))
return res
def _start(self, cr, uid, ids, context):
"""
Returns login if already there in the selected record.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: List of ids
@param context: A standard dictionary
@return: login field from current record.
"""
lots_obj = self.pool.get('auction.lots')
for rec in lots_obj.browse(cr, uid, ids, context):
if (len(ids)==1) and (not rec.ach_uid and not rec.ach_login):
raise osv.except_osv('Error', 'No buyer is set for this lot.')
if not rec.ach_uid and rec.ach_login:
return {'ach_login': rec.ach_login}
return {}
def buyer_map_set(self, cr, uid, ids, context):
"""
To map the buyer and login name.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: List of ids
@param context: A standard dictionary
@return:
"""
rec_ids = context and context.get('active_ids',False) or False
assert rec_ids, _('Active IDs not Found')
datas = self.read(cr, uid, ids[0],['ach_login','ach_uid'])
lots_obj = self.pool.get('auction.lots')
recs = lots_obj.browse(cr, uid, rec_ids, context)
for rec in recs:
if rec.ach_login==datas['ach_login']:
lots_obj.write(cr, uid, [rec.id], {'ach_uid': datas['ach_uid']}, context=context)
cr.commit()
return {}
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
context=None, toolbar=False, submenu=False):
"""
Changes the view dynamically
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return: New arch of view.
"""
record_ids = context and context.get('active_ids', False) or False
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)
lots_obj = self.pool.get('auction.lots')
if record_ids:
for lots in lots_obj.browse(cr, uid, record_ids):
print "lotslotslotslots",lots
if lots.ach_uid:
res['arch'] = """
<form title="Mapping Result">
<group col="2" colspan="2">
<label string="All objects are assigned to buyers !"/>
<newline/>
<button icon='gtk-cancel' special="cancel"
string="Done" />
</group>
</form>
"""
return res
wiz_auc_lots_buyer_map()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Auction lots send result -->
<record id="view_auction_buyer_map" model="ir.ui.view">
<field name="name">Map buyer username to Partners</field>
<field name="model">auction.lots.buyer_map</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Buyer Map" >
<field name="ach_login" colspan="4"/>
<newline/>
<field name="ach_uid" colspan="4"/>
<separator colspan="4"/>
<group col="4" colspan="4">
<button icon='gtk-cancel' special="cancel"
string="Exit" />
<button name="buyer_map_set" string="Update"
colspan="2" type="object" icon="gtk-go-forward" />
</group>
</form>
</field>
</record>
<act_window name="Map buyer username to Partners"
res_model="auction.lots.buyer_map"
src_model="auction.lots"
view_mode="form"
target="new"
key2="client_action_multi"
id="action_view_auction_buyer_map"/>
</data>
</openerp>

View File

@ -1,107 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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/>.
#
##############################################################################
import wizard
import netsvc
import pooler
import sql_db
buyer_map = '''<?xml version="1.0"?>
<form title="Buyer Map">
<field name="ach_login"/>
<newline/>
<field name="ach_uid"/>
</form>'''
buyer_map_fields = {
'ach_login': {'string':'Buyer Username', 'type':'char', 'size':64, 'required':True},
'ach_uid': {'string':'Buyer', 'type':'many2one', 'required':True, 'relation':'res.partner'},
}
#
# Try to find an object not mapped
#
def _state_check(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
cr.execute('select id from auction_lots where (ach_uid is null and ach_login is not null) ')
v_ids=[x[0] for x in cr.fetchall()]
#ids_not_mapped=pool.get('auction.lots').search(cr,uid,[('rec.ach_uid','=',False)])
for rec in pool.get('auction.lots').browse(cr,uid,v_ids,context):
# if not rec.ach_uid and not rec.ach_login:
# raise wizard.except_wizard ('Error','No username is associated to this lot!')
if (not rec.ach_uid or not rec.ach_login):
return 'check'
return 'done'
def _start(self,cr,uid,datas,context):
pool = pooler.get_pool(cr.dbname)
for rec in pool.get('auction.lots').browse(cr,uid,datas['ids'],context):
if (len(datas['ids'])==1) and (not rec.ach_uid and not rec.ach_login):
raise wizard.except_wizard('Error', 'No buyer setted for this lot')
if not rec.ach_uid and rec.ach_login:
return {'ach_login': rec.ach_login}
for rec in pool.get('auction.lots').browse(cr,uid,datas['ids'],context):
if (not rec.ach_uid and rec.ach_login):
return {'ach_login': rec.ach_login}
return {}
def _buyer_map_set(self,cr, uid, datas,context):
pool = pooler.get_pool(cr.dbname)
recs=pool.get('auction.lots').browse(cr,uid,datas['ids'],context)
for rec in recs:
if rec.ach_login==datas['form']['ach_login']:
pool.get('auction.lots').write(cr, uid, [rec.id], {'ach_uid': datas['form']['ach_uid']}, context=context)
cr.commit()
return {'ach_login':False, 'ach_uid':False}
class wiz_auc_lots_buyer_map(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'choice', 'next_state':_state_check}
},
'check': {
'actions': [_start],
'result': {'type': 'form', 'arch':buyer_map, 'fields': buyer_map_fields, 'state':[('end','Exit'),('set_buyer', 'Update')]}
},
'set_buyer': {
'actions': [_buyer_map_set],
'result': {'type': 'state', 'state':'init'}
},
'done': {
'actions': [_start],
'result': {
'type': 'form',
'arch':'''<?xml version="1.0"?>
<form title="Mapping result">
<label string="All objects are assigned to buyers !"/>
</form>''',
'fields': {},
'state':[('end','Close')]}
}
}
wiz_auc_lots_buyer_map('auction.lots.buyer_map')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: