[IMP] Add maintenance.contract.module to store the modules in the maintenance contract
[IMP] Use a fields.many2many instead of a fields.text for the module list in the maintenance.contract bzr revid: stephane@tinyerp.com-20081203104419-64mrmq6qmjhv553k
This commit is contained in:
parent
e8b1fbcda9
commit
d06bd52c36
|
@ -37,6 +37,16 @@ from pprint import pprint as pp
|
|||
from tools import config
|
||||
import xmlrpclib
|
||||
|
||||
class maintenance_contract_module(osv.osv):
|
||||
_name ="maintenance.contract.module"
|
||||
_description = "maintenance contract modules"
|
||||
_columns = {
|
||||
'name' : fields.char('Name', size=128, required=True),
|
||||
'version': fields.char('Version', size=64,),
|
||||
}
|
||||
|
||||
maintenance_contract_module()
|
||||
|
||||
class maintenance_contract(osv.osv):
|
||||
_name = "maintenance.contract"
|
||||
_description = "Maintenance Contract"
|
||||
|
@ -45,7 +55,7 @@ class maintenance_contract(osv.osv):
|
|||
'password' : fields.char('Password', size=64, invisible=True, required=True, readonly=True),
|
||||
'date_start' : fields.date('Starting Date', readonly=True),
|
||||
'date_stop' : fields.date('Ending Date', readonly=True),
|
||||
'modules': fields.text('Covered Modules')
|
||||
'module_ids' : fields.many2many('maintenance.contract.module', 'maintenance_contract_module_rel', 'contract_id', 'module_id', 'Covered Modules', readonly=True),
|
||||
}
|
||||
_defaults = {
|
||||
'password' : lambda obj,cr,uid,context={} : '',
|
||||
|
@ -78,20 +88,32 @@ class maintenance_contract_wizard(osv.osv_memory):
|
|||
rpc = xmlrpclib.ServerProxy('http://%s:%d/xmlrpc/common' % (remote_server, port))
|
||||
ruid = rpc.login(remote_db, login, password)
|
||||
rpc = xmlrpclib.ServerProxy('http://%s:%d/xmlrpc/object' % (remote_server, port))
|
||||
res = rpc.execute(remote_db, ruid, password,
|
||||
contract_info = rpc.execute(remote_db, ruid, password,
|
||||
'maintenance.maintenance', 'get_module_for_contract', contract['name'], contract['password'])
|
||||
if res:
|
||||
if contract_info:
|
||||
if contract_info['modules']:
|
||||
module_ids = []
|
||||
for name, version in contract_info['modules']:
|
||||
contract_module = self.pool.get('maintenance.contract.module')
|
||||
res = contract_module.search(cr, uid, [('name', '=', name),('version', '=', version)])
|
||||
if not res:
|
||||
id = contract_module.create(cr, uid, { 'name' : name, 'version' : version } )
|
||||
else:
|
||||
id = res[0]
|
||||
module_ids.append(id)
|
||||
|
||||
self.pool.get('maintenance.contract').create(
|
||||
cr,
|
||||
uid, {
|
||||
'name' : contract['name'],
|
||||
'password' : contract['password'],
|
||||
'date_start' : res['date_from'],
|
||||
'date_stop' : res['date_to'],
|
||||
'date_start' : contract_info['date_from'],
|
||||
'date_stop' : contract_info['date_to'],
|
||||
'module_ids' : [(6,0,module_ids)],
|
||||
}
|
||||
)
|
||||
|
||||
return self.write(cr, uid, ids, {'state' : ('unvalidated', 'validated')[bool(res)] }, context=context)
|
||||
return self.write(cr, uid, ids, {'state' : ('unvalidated', 'validated')[bool(contract_info)] }, context=context)
|
||||
|
||||
maintenance_contract_wizard()
|
||||
|
||||
|
|
|
@ -26,7 +26,12 @@
|
|||
<field name="date_start" select="1"/>
|
||||
<field name="date_stop" select="1"/>
|
||||
<separator string="Covered Modules" colspan="4"/>
|
||||
<field name="modules" nolabel="1" colspan="4"/>
|
||||
<field name="module_ids" nolabel="1" colspan="4">
|
||||
<tree string="Covered Modules">
|
||||
<field name="name" />
|
||||
<field name="version" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
|
Loading…
Reference in New Issue