[IMP] account: Hide the company_id only if there is a default company (only one)

bzr revid: stw@openerp.com-20111026145643-nw9rza8g8u08i7bg
This commit is contained in:
Stephane Wirtel 2011-10-26 16:56:43 +02:00
parent f24c63436c
commit 33a6d24bcd
2 changed files with 8 additions and 1 deletions

View File

@ -28,7 +28,8 @@
<field name="charts"/>
<group colspan="4" groups="account.group_account_user">
<separator col="4" colspan="4" string="Configure Fiscal Year"/>
<field name="company_id" colspan="4" widget="selection"/><!-- we assume that this wizard will be run only by administrators and as this field may cause problem if hidden (because of the default company of the user removed from the selection because already configured), we simply choosed to remove the group "multi company" of it -->
<field name="has_default_company" invisible="1" />
<field name="company_id" colspan="4" widget="selection" attrs="{'invisible' : [('has_default_company', '=', True)]}"/><!-- we assume that this wizard will be run only by administrators and as this field may cause problem if hidden (because of the default company of the user removed from the selection because already configured), we simply choosed to remove the group "multi company" of it -->
<field name="date_start" on_change="on_change_start_date(date_start)"/>
<field name="date_stop"/>
<field name="period" colspan="4"/>

View File

@ -59,12 +59,17 @@ class account_installer(osv.osv_memory):
'sale_tax': fields.float('Sale Tax(%)'),
'purchase_tax': fields.float('Purchase Tax(%)'),
'company_id': fields.many2one('res.company', 'Company', required=True),
'has_default_company' : fields.boolean('Has Default Company', readonly=True),
}
def _default_company(self, cr, uid, context=None):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
return user.company_id and user.company_id.id or False
def _default_has_default_company(self, cr, uid, context=None):
count = self.pool.get('res.company').search_count(cr, uid, [], context=context)
return bool(count == 1)
_defaults = {
'date_start': lambda *a: time.strftime('%Y-01-01'),
'date_stop': lambda *a: time.strftime('%Y-12-31'),
@ -72,6 +77,7 @@ class account_installer(osv.osv_memory):
'sale_tax': 0.0,
'purchase_tax': 0.0,
'company_id': _default_company,
'has_default_company': _default_has_default_company,
'charts': 'configurable'
}