def default_to_dt(cr, uid, ids, fiscalyear_id, context=None):
     if fiscalyear_id:
         fy_pool = pooler.get_pool(cr.dbname).get('account.fiscalyear')
         fy = fy_pool.browse(cr, uid, fiscalyear_id, context=context)
         return str(min(dt(fy.date_stop), date.today()))
     else:
         return str(date.today())
 def default_to_dt(cr, uid, ids, fiscalyear_id, context=None):
     if fiscalyear_id:
         fy_pool = pooler.get_pool(cr.dbname).get('account.fiscalyear')
         fy = fy_pool.browse(cr, uid, fiscalyear_id, context=context)
         return str(min(dt(fy.date_stop), date.today()))
     else:
         return str(date.today())
    def default_to_period_id(cr, uid, ids, fiscalyear_id, context=None):
        if fiscalyear_id:
            fy_pool = pooler.get_pool(cr.dbname).get('account.fiscalyear')
            fy = fy_pool.browse(cr, uid, fiscalyear_id, context=context)
            stop_date = min(dt(fy.date_stop), date.today())

            p_pool = pooler.get_pool(cr.dbname).get('account.period')
            p_ids = p_pool.search(cr, uid, [('fiscalyear_id','=',fiscalyear_id),
                                            ('date_start','<=',stop_date),
                                            ('date_stop','>=',stop_date)], context=context)
            return p_ids[0]
        else:
            return False
    def default_to_period_id(cr, uid, ids, fiscalyear_id, context=None):
        if fiscalyear_id:
            fy_pool = pooler.get_pool(cr.dbname).get('account.fiscalyear')
            fy = fy_pool.browse(cr, uid, fiscalyear_id, context=context)
            stop_date = min(dt(fy.date_stop), date.today())

            p_pool = pooler.get_pool(cr.dbname).get('account.period')
            p_ids = p_pool.search(cr,
                                  uid, [('fiscalyear_id', '=', fiscalyear_id),
                                        ('date_start', '<=', stop_date),
                                        ('date_stop', '>=', stop_date)],
                                  context=context)
            return p_ids[0]
        else:
            return False