diff options
| author | Christophe Simonis <christophe@tinyerp.com> | 2009-04-29 18:13:19 +0200 |
|---|---|---|
| committer | Christophe Simonis <christophe@tinyerp.com> | 2009-04-29 18:13:19 +0200 |
| commit | 6d553a36fda98f2efa61d2a957dd94ad67eb8c1a (patch) | |
| tree | f9a28cc9906a3e395bb9a5376654b025003f7c64 /addons/base_setup/wizard/wizard_base_setup.py | |
| parent | 9fe84757c9ecbeaacf21a7a8b68142c1cadf3fcc (diff) | |
[IMP] base_setup: pre-fill the fields with the address of the main company
bzr revid: christophe@tinyerp.com-20090429161319-3jh2wmde29myy6l7
Diffstat (limited to 'addons/base_setup/wizard/wizard_base_setup.py')
| -rw-r--r-- | addons/base_setup/wizard/wizard_base_setup.py | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/addons/base_setup/wizard/wizard_base_setup.py b/addons/base_setup/wizard/wizard_base_setup.py index 10c75bd092e..f095e4b78cb 100644 --- a/addons/base_setup/wizard/wizard_base_setup.py +++ b/addons/base_setup/wizard/wizard_base_setup.py @@ -111,43 +111,51 @@ class wizard_base_setup(wizard.interface): return res def _get_company(self, cr, uid, data, context): - pool=pooler.get_pool(cr.dbname) - company_obj=pool.get('res.company') + pool = pooler.get_pool(cr.dbname) + company_obj = pool.get('res.company') ids=company_obj.search(cr, uid, []) if not ids: return {} - company=company_obj.browse(cr, uid, ids)[0] - self.fields['name']['default']=company.name - self.fields['currency']['default']=company.currency_id.id - serv_pro_id = pooler.get_pool(cr.dbname).get('ir.module.module').search(cr, uid, [('name','=','profile_service')]) or False - if serv_pro_id: - return {'profile':serv_pro_id[0]} - return {} + company = company_obj.browse(cr, uid, ids)[0] + + res = { + 'name': company.name, + 'currency': company.currency_id.id, + } - def _get_states(self, cr, uid, context): - pool=pooler.get_pool(cr.dbname) - state_obj=pool.get('res.country.state') - ids=state_obj.search(cr, uid, []) - res=[(state.id, state.name) for state in state_obj.browse(cr, uid, ids, context=context)] + if company.partner_id.address: + address = company.partner_id.address[0] + for field in 'street street2 zip city email phone'.split(): + res[field] = address[field] + + for field in 'country_id state_id'.split(): + if address[field]: + res[field] = address[field].id + + serv_pro_id = pool.get('ir.module.module').search(cr, uid, [('name','=','profile_service')]) or False + if serv_pro_id: + res['profile'] = serv_pro_id[0] + + return res + + + def _get_all(self, cr, uid, context, model): + pool = pooler.get_pool(cr.dbname) + obj = pool.get(model) + ids = obj.search(cr, uid, []) + res = [(o.id, o.name) for o in obj.browse(cr, uid, ids, context=context)] res.append((-1, '')) - res.sort(lambda x,y: cmp(x[1],y[1])) + res.sort(key=lambda x: x[1]) return res + def _get_states(self, cr, uid, context): + return self._get_all(cr, uid, context, 'res.country.state') + def _get_countries(self, cr, uid, context): - pool=pooler.get_pool(cr.dbname) - country_obj=pool.get('res.country') - ids=country_obj.search(cr, uid, []) - res=[(country.id, country.name) for country in country_obj.browse(cr, uid, ids, context=context)] - res.sort(lambda x,y: cmp(x[1],y[1])) - return res + return self._get_all(cr, uid, context, 'res.country') def _get_currency(self, cr, uid, context): - pool=pooler.get_pool(cr.dbname) - currency_obj=pool.get('res.currency') - ids=currency_obj.search(cr, uid, []) - res=[(currency.id, currency.name) for currency in currency_obj.browse(cr, uid, ids, context=context)] - res.sort(lambda x,y: cmp(x[1],y[1])) - return res + return self._get_all(cr, uid, context, 'res.currency') def _update(self, cr, uid, data, context): pool=pooler.get_pool(cr.dbname) @@ -256,7 +264,6 @@ class wizard_base_setup(wizard.interface): 'string':'Profile', 'type':'selection', 'selection':_get_profiles, -# 'default': _get_service_profile, 'required': True, }, |
