[IMP]: implement onchange_date, to select period depends on the date

bzr revid: mga@tinyerp.com-20100813210842-9rxzooh86329csns
This commit is contained in:
Mantavya Gajjar 2010-08-14 02:38:42 +05:30
parent 4e5f5bae3f
commit bdaee0229f
2 changed files with 26 additions and 1 deletions

View File

@ -150,6 +150,31 @@ class account_voucher(osv.osv):
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
}
def onchange_date(self, cr, user, ids, date, context={}):
"""
Returns a dict that contains new values and context
@param cr: A database cursor
@param user: ID of the user currently logged in
@param date: latest value from user input for field date
@param args: other arguments
@param context: context arguments, like lang, time zone
@return: Returns a dict which contains new values, and context
"""
res = {}
period_pool = self.pool.get('account.period')
pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)])
if pids:
res.update({
'period_id':pids[0]
})
context.update({
'period_id':pids[0]
})
return {
'value':res,
'context':context,
}
def onchange_account(self, cr, uid, ids, account_id):
if not account_id:
return {

View File

@ -54,7 +54,7 @@
<group col="2" colspan="1">
<separator string="Other Informtion" colspan="2"/>
<field name="reference" select="1"/>
<field name="date" select="1"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="currency_id" select="1"/>
</group>
</page>