Beispiel #1
0
class md_hr_contract_availability(osv.osv):
    _name = 'md.hr.contract.availability'
    _description = 'HR Contract Availability'
    _columns = {
        'contract_id':
        fields.many2one('hr.contract', 'Contract'),
        'day':
        fields.selection([('sun', 'Sunday'), ('mon', 'Monday'),
                          ('tue', 'Tuesday'), ('wed', 'Wednesday'),
                          ('thu', 'Thursday'), ('fri', 'Friday'),
                          ('sat', 'Saturday')], 'Day'),
        'from_hour':
        fields.time('From'),
        'to_hour':
        fields.time('To'),
    }
    _defaults = {'day': lambda *a: 'sun'}
Beispiel #2
0
class Company(osv.osv):
    """
    These fields are used in the comptation of an order duration.
    """

    _inherit = 'res.company'
    _columns = {
        'rent_morning_begin':
        fields.time(
            'Day begin',
            required=True,
            help=
            "This time will be used as default rent begin date/time if you select 'Tomorrow (Morning)' as default value."
        ),
        'rent_afternoon_begin':
        fields.time(
            'Afternoon begin',
            required=True,
            help=
            "This time will be used as default rent begin date/time if you select 'Tomorrow (Afternoon)' as default value."
        ),
        'rent_afternoon_end':
        fields.time(
            'Afternoon end',
            required=True,
            help="This time will be used as the time of the rent end date."),
        'rent_default_begin':
        fields.selection(
            DEFAULT_BEGIN,
            'Rent default begin/shipping',
            required=True,
            help=
            "Specify the default rent begin date/time value you want to have when you create a new rent order."
        )
    }
    _defaults = {
        'rent_morning_begin': '09:00:00',
        'rent_afternoon_begin': '14:00:00',
        'rent_afternoon_end': '19:00:00',
        'rent_default_begin': 'today',
    }
class fleet_fuellog(osv.osv):
    _description = 'fleet fuellog Inheritance'
    _inherit = 'fleet.fuellog'

    _columns = {
        'log_no':
        fields.char('Log Entry#', size=24),
        'vendor':
        fields.many2one('res.partner', 'Fuel Station', size=10),
        'supplier':
        fields.many2one('stock.location', 'Supplier Station'),
        'engine':
        fields.float('Engine Hours', digits=(16, 2)),
        'emp_resp':
        fields.many2one('hr.employee',
                        'Employee Responsible',
                        help="Employee reporting fuelling details"),
        'driver':
        fields.many2one(
            'hr.employee',
            'Driver',
            help="Driver who has driven the vehice before this fuelling"),
        'd_number':
        fields.char('Driver Number', size=20),
        'invno':
        fields.many2one('account.invoice', 'Invoice no', size=10),
        'journal_id':
        fields.many2one('account.journal', 'Journal'),
        'move_id':
        fields.many2one('account.move', 'Account Entry'),
        'period_id':
        fields.many2one('account.period', 'Period'),
        'date':
        fields.date('Transaction Date', required=True),
        'time':
        fields.time('Transaction Time', required=True),
        'cost':
        fields.float('Cost Per Ltr', digits=(16, 2), required=True),
    }
Beispiel #4
0
class mrp_workcenter_registry(osv.osv):
    _description = 'MRP Workcenter Registry'
    _name = 'mrp.workcenter.registry'

    _columns = {
        'key':
        fields.many2one('mrp.workcenter.registry.key', 'Key'),
        'workcenter_line_id':
        fields.many2one('mrp.production.workcenter.line', 'Workcenter'),
        'product_id':
        fields.many2one('product.product', 'Product'),
        'name':
        fields.char('Operation Code', size=64, required=True),
        'workcenter_id':
        fields.many2one('mrp.workcenter', 'Resource'),
        'de_product_qty':
        fields.float('Defective Product Qty', multi='sums'),
        'go_product_qty':
        fields.float('Good Product Qty', multi='sums'),
        'date_start':
        fields.date('Date start'),
        'time_start':
        fields.time('Time start'),
        'date_stop':
        fields.date('Date stop'),
        'time_stop':
        fields.time('Time stop'),
        'note':
        fields.text('Notes'),
        'operator_registry_id':
        fields.many2one('mrp.operator.registry',
                        'Operator registry',
                        ondelete='cascade'),
        'production_id':
        fields.many2one('mrp.production',
                        'Manufacturing Order',
                        ondelete='set null'),
        'operator_id':
        fields.related('operator_registry_id',
                       'operator_id',
                       type='many2one',
                       relation='hr.employee',
                       string='Operator'),
    }

    _defaults = {
        'name': '/',
        'date_start': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
        'date_stop': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
    }

    def workcenter_line_change(self,
                               cr,
                               uid,
                               ids,
                               workcenter_line_id,
                               context={}):
        if (workcenter_line_id):
            workcenter_line = self.pool.get(
                'mrp.production.workcenter.line').browse(
                    cr, uid, [workcenter_line_id], context)[0]
            return {
                'value': {
                    'workcenter_line_id': workcenter_line.id,
                    'product_id': workcenter_line.production_id.product_id.id,
                    'name': workcenter_line.name,
                    'workcenter_id': workcenter_line.workcenter_id.id,
                    'production_id': workcenter_line.production_id.id
                }
            }
Beispiel #5
0
class buyout_config(osv.osv):
    """买断信息设置"""
    _name = "ktv.buyout_config"
    _description = "包厢买断信息设置"
    _fee_fields = [
        #周一
        "mon_buyout_fee",
        #周二
        "tue_buyout_fee",
        #周三
        "wed_buyout_fee",
        #周四
        "thu_buyout_fee",
        #周五
        "fri_buyout_fee",
        #周六
        "sat_buyout_fee",
        #周日
        "sun_buyout_fee",
        #特殊日
        "special_day_buyout_fee",
    ]
    _buyout_enable_fields = [
        #周一
        "mon_buyout_enable",
        #周二
        "tue_buyout_enable",
        #周三
        "wed_buyout_enable",
        #周四
        "thu_buyout_enable",
        #周五
        "fri_buyout_enable",
        #周六
        "sat_buyout_enable",
        #周日
        "sun_buyout_enable",
    ]

    _columns = {
        field_name: fields.float(
            field_name,
            digits_compute=dp.get_precision('Ktv Room Default Precision'),
            required=True)
        for field_name in _fee_fields
    }
    _columns.update({
        field_name: fields.boolean(field_name)
        for field_name in _buyout_enable_fields
    })
    _columns.update({
        "name":
        fields.char("name", size=64, required=True),
        #包厢类别
        "room_type_id":
        fields.many2one("ktv.room_type",
                        "room_type_id",
                        required=True,
                        help="请选择包厢类别"),
        "is_member":
        fields.boolean("is_member", help="是否是会员专用买断"),
        #买断时间限制
        "time_from":
        fields.time("time_from", required=True, help="买断起始时间"),
        "time_to":
        fields.time("time_to", required=True, help="买断结束时间"),
        #FIXME 截止时间,感觉多余,不使用
        "break_on":
        fields.time("break_on", help="该固定时长买断每天截止时间,即使买断未到点,截止时间一到也即刻结束"),
        #FIXME 多余字段,将删除 是否启用截止时间
        "break_on_enable":
        fields.boolean("break_on_active"),
        #买断时长,以小时为单位
        "buyout_time":
        fields.integer('buyout_time'),
        'active':
        fields.boolean('active'),
        'test_time':
        fields.time('test_time'),
        'test_datetime':
        fields.datetime('test_datetime'),
    })

    _defaults = {field_name: 0 for field_name in _fee_fields}

    _defaults.update(
        {field_name: True
         for field_name in _buyout_enable_fields})

    _defaults.update({
        "is_member": False,
        "active": True,
    })

    def get_active_configs(self, cr, uid, room_type_id):
        '''
        获取当前有效的买断设置信息
        :params integer room_type_id 包厢类型id
        :params integer buyout_config_id 买断设置id
        :return array 符合条件的买断信息数组
        '''
        ret = []
        #1 获取所有买断信息,并逐个进行判断
        ids = self.search(cr, uid, [("room_type_id", '=', room_type_id)])
        configs = self.browse(cr, uid, ids)
        #2 判断当日买断是否启用
        context_now = ktv_helper.user_context_now(self, cr, uid)
        #判断是周几
        weekday_str = ktv_helper.weekday_str(context_now.weekday())
        now_str = datetime.now().strftime("%H:%M:00")
        #判断特殊日设置
        s_day_ids = self.pool.get('ktv.buyout_config_special_day').search(
            cr, uid, [("room_type_id", '=', room_type_id)])
        s_days = self.pool.get('ktv.buyout_config_special_day').read(
            cr, uid, s_day_ids, ['room_type_id', 'special_day'])
        s_days_list = [s_day['special_day'] for s_day in s_days]

        #买断起止时间
        #time_from 当前时间
        #time_to 买断结束时间
        #如果当日是特殊日,则直接返回所有买断设置
        in_sp_day = datetime.today() in s_days_list
        #根据设置的星期是否有效来得到返回的设置
        for c in configs:
            buyout_enable = getattr(c, weekday_str + '_buyout_enable', False)
            in_time_range = ktv_helper.utc_time_between(
                c.time_from, c.time_to, now_str)
            time_from = datetime.now()
            time_to = ktv_helper.str_to_today_time(c.time_to)

            if (in_sp_day and in_time_range) or (buyout_enable
                                                 and in_time_range):
                buyout_fee = getattr(c, weekday_str + "_buyout_fee", 0.0)
                if in_sp_day:
                    buyout_fee = getattr(c, "special_day_buyout_fee")
                ret.append({
                    "id":
                    c.id,
                    "room_type_id":
                    c.room_type_id.id,
                    "name":
                    getattr(c, "name"),
                    #起始时间是当前时间
                    "time_from":
                    time_from.strftime('%Y-%m-%d %H:%M:%S'),
                    "time_to":
                    time_to.strftime('%Y-%m-%d %H:%M:%S'),
                    "is_member":
                    getattr(c, 'is_member'),
                    "buyout_fee":
                    buyout_fee,
                    #计算实际买断分钟数量
                    "buyout_time": (time_to.hour - time_from.hour) * 60 +
                    (time_to.minute - time_from.minute)
                })
        return ret

    def get_active_buyout_fee(self, cr, uid, buyout_config_id, context=None):
        '''
        获取当前有效的买断费用信息,需要判断如下情况
        1、当前日期是否在买断设置日期范围内
        2、当前时间是否在买断规定时间段内
        3、另:还需判断特殊日设置
        4、另:还需判断是否会员设置
        '''
        config = self.browse(cr, uid, buyout_config_id)
        active_buyout_configs = self.get_active_configs(
            cr, uid, config.room_type_id.id)

        _logger.debug(buyout_config_id)
        _logger.debug(active_buyout_configs)
        ret = [c for c in active_buyout_configs if c['id'] == buyout_config_id]
        if not active_buyout_configs or not ret:
            raise osv.except_osv(_("错误"), _('当前选择的买断设置信息无效.'))
        return ret[0]
Beispiel #6
0
class hourly_fee_promotion(osv.osv):
    '''买钟优惠设置'''
    _name = "ktv.hourly_fee_promotion"
    _description = "买钟优惠设置"

    _columns = {
            "name" : fields.char("name",size = 64,required = True),
            "description" : fields.text("description",size = 255),
            "active" : fields.boolean("active"),
            "is_member" : fields.boolean("is_member",help = "是否会员专属优惠"),
            "buy_minutes" : fields.integer("buy_minutes",help = "买钟时长(分钟)"),
            "present_minutes" :fields.integer("present_minutes",help = "赠送时长(分钟)"),
            "active_datetime_limit" : fields.boolean("active_datetime_limit",help = "是否启用日期区间限制"),
            "datetime_from" : fields.datetime("datetime_from",help = "起始日期"),
            "datetime_to" : fields.datetime('datetime_to',help = "结束日期"),
            "active_time_limit" : fields.boolean("active_time_limit",help = "是否启用时间段限制"),
            "time_from" : fields.time("time_from",help = "起始时间"),
            "time_to" : fields.time("time_to",help = "结束时间"),
            #暂不启用以下字段
            "active_break_on_time" :  fields.boolean("active_break_on_time",help = "启用优惠截止时间"),
            "break_on_time" : fields.time("break_on_time",help = "优惠截止时间"),
            #
            "mon_active": fields.boolean("mon_active"),
            "tue_active": fields.boolean("tue_active"),
            "wed_active": fields.boolean("wed_active"),
            "thu_active": fields.boolean("thu_active"),
            "fri_active": fields.boolean("fri_active"),
            "sat_active": fields.boolean("sat_active"),
            "sun_active": fields.boolean("sun_active"),
            }

    _defaults = {
            "is_member" : False,
            "active" : True,
            "active_datetime_limit" : False,
            "active_time_limit" : False,
            "active_break_on_time" : False,
            "mon_active": True,
            "tue_active": True,
            "wed_active": True,
            "thu_active": True,
            "fri_active": True,
            "sat_active": True,
            "sun_active": True,
            }
    def get_active_configs(self,cr,uid):
        """
        获取当前有效的买钟优惠设置信息
        """
        #默认情况下,所有设置都起效
        ret = []
        ids = self.search(cr,uid,[])
        configs = self.browse(cr,uid,ids)

        context_now = ktv_helper.user_context_now(self,cr,uid)
        #判断是周几
        weekday_str = ktv_helper.weekday_str(context_now.weekday())
        time_now_str = datetime.now().strftime("%H:%M:00")

        datetime_now_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        for c in configs:
            json_c = {
                    "id": c.id,
                    "name" : c.name,
                    "is_member" : c.is_member,
                    "buy_minutes": c.buy_minutes,
                    "present_minutes": c.present_minutes,
                    "active_datetime_limit" : c.active_datetime_limit,
                    "datetime_from" : c.datetime_from,
                    "datetime_to" : c.datetime_to,
                    "active_time_limit": c.active_time_limit,
                    "time_from": c.time_from,
                    "time_to": c.time_to,

                    }
            #判断是否在日期区间内
            if c.active_datetime_limit and (not datetime_now_str >= c.datetime_from or not datetime_now_str <= c.datetime_to):
                json_c = None
            #判断是否在时间区间内
            if c.active_time_limit and ktv_helper.htc_time_between(c.time_from,c.time_to,time_now_str):
                json_c = None
            #判断是否启用了星期设置
            if c.mon_active or c.tue_active or c.wed_active or c.thu_active or c.fri_active or c.sat_active or c.sun_active:
                if not getattr(c,"%s_active" % weekday_str):
                    json_c = None
            ret.append(json_c)
            return ret
class minimum_fee_config(osv.osv):
    """针对收取最低消费的量贩KTV而言,可能存在不同时段其包厢的不一样,在此可以对包厢设置不同时段的最低消费、包厢费、按位低销及开房套餐等参数,系统按时间自动选取场次对应的设置"""
    _name = "ktv.minimum_fee_config"
    _description = "时段低消设置"
    _fee_fields = [
        "mon_minimum_fee",
        "mon_room_fee",
        "mon_minimum_fee_p",
        "tue_minimum_fee",
        "tue_room_fee",
        "tue_minimum_fee_p",
        "wed_minimum_fee",
        "wed_room_fee",
        "wed_minimum_fee_p",
        "thu_minimum_fee",
        "thu_room_fee",
        "thu_minimum_fee_p",
        "fri_minimum_fee",
        "fri_room_fee",
        "fri_minimum_fee_p",
        "sat_minimum_fee",
        "sat_room_fee",
        "sat_minimum_fee_p",
        "sun_minimum_fee",
        "sun_room_fee",
        "sun_minimum_fee_p",
        "special_day_minimum_fee",
        "special_day_room_fee",
        "special_day_minimum_fee_p",
    ]
    _columns = {
        field_name: fields.float(
            field_name,
            digits_compute=dp.get_precision('Ktv Room Default Precision'),
            required=True)
        for field_name in _fee_fields
    }
    _columns.update({
        #包厢类别
        "room_type_id":
        fields.many2one("ktv.room_type", "room_type_id", required=True),
        #打折时间限制
        "time_from":
        fields.time("time_from", required=True),
        #打折消费时间结束值
        "time_to":
        fields.time("time_to", required=True),
        "active":
        fields.boolean("active"),
    })
    _defaults = {"active": True}
    _defaults.update({field_name: 0 for field_name in _fee_fields})

    def get_active_configs(self, cr, uid, room_type_id):
        """
        获取当前设定的包厢类别可用的低消设置信息
        params: room_type_id integer 包厢类别id
        return: array 符合条件的低消设置信息
        """
        ret = []
        #1 获取所有买断信息,并逐个进行判断
        ids = self.search(cr, uid, [("room_type_id", '=', room_type_id)])
        configs = self.browse(cr, uid, ids)
        #2 判断当日买断是否启用
        context_now = ktv_helper.user_context_now(self, cr, uid)
        #判断是周几
        weekday_str = ktv_helper.weekday_str(context_now.weekday())
        now_str = datetime.now().strftime("%H:%M:00")
        #判断特殊日设置
        s_day_ids = self.pool.get('ktv.minimum_fee_config_special_day').search(
            cr, uid, [("room_type_id", '=', room_type_id)])
        s_days = self.pool.get('ktv.minimum_fee_config_special_day').read(
            cr, uid, s_day_ids, ['room_type_id', 'special_day'])
        s_days_list = [s_day['special_day'] for s_day in s_days]

        #如果当日是特殊日,则直接返回所有买断设置
        in_sp_day = datetime.today() in s_days_list
        #根据设置的星期是否有效来得到返回的设置
        for c in configs:
            in_time_range = ktv_helper.utc_time_between(
                c.time_from, c.time_to, now_str)
            if (in_sp_day and in_time_range) or in_time_range:
                room_fee = getattr(c, weekday_str + "_room_fee", 0.0)
                minimum_fee = getattr(c, weekday_str + "_minimum_fee", 0.0)
                minimum_fee_p = getattr(c, weekday_str + "_minimum_fee_p", 0.0)
                if in_sp_day:
                    room_fee = getattr(c, "special_day_room_fee", 0.0)
                    minimum_fee = getattr(c, "special_day_minimum_fee", 0.0)
                    minimum_fee_p = getattr(c, "special_day_minimum_fee_p",
                                            0.0)
                ret.append({
                    "id": c.id,
                    "room_type_id": c.room_type_id.id,
                    "room_fee": room_fee,
                    "minimum_fee": minimum_fee,
                    "minimum_fee_p": minimum_fee_p,
                })
        return ret
Beispiel #8
0
class hourly_fee_discount(osv.osv):
    """包厢钟点费打折设置,设置包厢每周各天的钟点费打折情况"""
    _name = "ktv.hourly_fee_discount"
    _description = "包厢钟点费打折设置,设置包厢每周各天的钟点费打折情况"
    #费用字段定义
    #其中discount字段存储的是百分比
    _fee_fields = [
            "mon_hourly_fee",
            "mon_hourly_discount",
            #周二
            "tue_hourly_fee",
            "tue_hourly_discount",
            #周三
            "wed_hourly_fee",
            "wed_hourly_discount",
            #周四
            "thu_hourly_fee",
            "thu_hourly_discount",
            #周五
            "fri_hourly_fee",
            "fri_hourly_discount",
            #周六
            "sat_hourly_fee",
            "sat_hourly_discount",
            #周日
            "sun_hourly_fee",
            "sun_hourly_discount",
            #特殊日
            "special_day_hourly_fee",
            "special_day_hourly_discount",
            ]

    _columns = { field_name : fields.float(field_name, digits_compute= dp.get_precision('Ktv Room Default Precision'),required = True) for field_name in _fee_fields}
    _columns.update({
            #价格类型
            "price_class_id" : fields.many2one("ktv.price_class","price_class_id",required = True),
            #包厢类别
            "room_type_id" : fields.many2one("ktv.room_type","room_type_id",required = True),
            #打折时间限制
            "time_from": fields.time("time_from",required = True ),
            #打折消费时间结束值
            "time_to": fields.time("time_to",required = True),
            #打折参考的基准价格,默认等于该包厢类别room_type的钟点费,用户可以修改
            "base_hourly_fee" : fields.float("base_hourly_fee", digits_compute= dp.get_precision('Ktv Room Default Precision')),
            })

    _defaults = { field_name : 0 for field_name in _fee_fields}

    _defaults.update({
        #打折参考的基准价格,默认等于该包厢类别room_type的钟点费,用户可以修改
        "base_hourly_fee" : 0,
        })

    #包厢类别发生变化,基准价格同样改变
    def onchange_room_type_id(self,cr,uid,ids,room_type_id):
        if not room_type_id:
            return {}
        room_type = self.pool.get('ktv.room_type').browse(cr, uid, room_type_id)
        vals = self._reset_discount_info(room_type.hourly_fee)
        vals.update({"base_hourly_fee" : room_type.hourly_fee})
        return {"value" : vals}

    #重新设置各天费用为100%
    def _reset_discount_info(self,base_hourly_fee = 0):
        vals = {field_name : base_hourly_fee for field_name in self._fee_fields if field_name.find("fee") != -1}
        vals.update({field_name : 100.0 for field_name in self._fee_fields if field_name.find("discount") != -1})
        return vals

    #基准钟点费发生变换时,充值所有打折数据
    def onchange_base_hourly_fee(self,cr,uid,ids,base_hourly_fee):
        if base_hourly_fee and base_hourly_fee == 0 :
            return {}
        vals = self._reset_discount_info(base_hourly_fee)
        return {"value" : vals}

    #钟点费或钟点费折扣互为变化
    #context中传递了变化的字段
    def onchange_hourly_fee(self,cr,uid,ids,field_name = False,hourly_fee_or_discount_rate = False ,base_hourly_fee = False,context = None):
        val ={}
        if not base_hourly_fee or not field_name :
            return {}
        #如果是修改钟点费,则自动计算折扣百分比
        precision_discount = self.pool.get('decimal.precision').precision_get(cr, uid, 'Ktv Fee Discount Rate')
        precision_fee = self.pool.get('decimal.precision').precision_get(cr, uid, 'Ktv Fee')
        if field_name.find("hourly_fee") != -1 :
            to_change_fieldname = field_name.replace('fee','discount')
            val[to_change_fieldname] = round(Decimal(hourly_fee_or_discount_rate) / Decimal(base_hourly_fee) * 100,precision_discount)

        #如果是修改钟点费折扣,则自动计算折扣后的钟点费
        if field_name.find("hourly_discount") != -1 :
            to_change_fieldname = field_name.replace('discount','fee')
            val[to_change_fieldname] = round(Decimal(base_hourly_fee) * Decimal(hourly_fee_or_discount_rate) / 100,precision_fee)
        return {"value" : val}

    def get_active_configs(self,cr,uid,room_type_id,context=None):
        """
        获取当前有效的钟点费打折设置信息
        :params room_type_id integer 包厢类别id M
        :params context['price_class_id'] integer 价格类别id O
        :params context['member_class_id'] integer 会员类别id O
        :return array 有效的钟点费打折信息数组
        """
        ret = []
        #1 获取所有钟点费打折信息,并逐个进行判断
        domain = [["room_type_id","=",room_type_id]]
        price_class_id = context and "price_class_id" in context and context['price_class_id']
        if price_class_id:
            domain.append(["price_class_id","=",price_class_id])
        member_class_id = context and "member_class_id" in context and context['member_class_id']
        if member_class_id:
            domain.append(["member_class_id","=",member_class_id])

        ids = self.search(cr,uid,domain)
        configs = self.browse(cr,uid,ids)
        #2 判断当日设置是否启用
        context_now = ktv_helper.user_context_now(self,cr,uid)
        #判断是周几
        weekday_str = ktv_helper.weekday_str(context_now.weekday())
        now_str = datetime.now().strftime("%H:%M:00")
        #判断特殊日设置
        which_fee =  context and 'which_fee' in context and context['which_fee'] or "hourly_fee_discount"
        osv_name = "ktv.%s_special_day" % which_fee
        s_day_ids = self.pool.get(osv_name).search(cr,uid,[("room_type_id",'=',room_type_id)])
        s_days = self.pool.get(osv_name).read(cr,uid,s_day_ids,['room_type_id','special_day'])
        s_days_list = [s_day['special_day'] for s_day in s_days]

        #如果当日是特殊日,则直接返回所有买断设置
        in_sp_day = datetime.today() in s_days_list
        #根据设置的星期是否有效来得到返回的设置
        for c in configs:
            in_time_range = ktv_helper.utc_time_between(c.time_from,c.time_to,now_str)
            #是否忽略时间段判断,用于显示全天的钟点费打折信息
            ignore_time_range = context and 'ignore_time_range' in context and context['ignore_time_range']
            if ignore_time_range:
                in_time_range = True
            if  (in_sp_day and in_time_range) or in_time_range:
                hourly_fee = getattr(c,weekday_str + "_hourly_fee",0.0)
                hourly_discount = getattr(c,weekday_str + "_hourly_discount",0.0)
                if in_sp_day:
                    hourly_fee = getattr(c,"special_day_hourly_fee")
                    hourly_discount = getattr(c,"special_day_hourly_discount")

                ret.append({
                    "id" : c.id,
                    "price_class_id" : c.price_class_id.id,
                    "room_type_id" : c.room_type_id.id,
                    "time_from" : c.time_from,
                    "time_to" : c.time_to,
                    "hourly_fee" : hourly_fee,
                    "hourly_discount" : hourly_discount,
                    })
        return ret
class vehicle_prev_op(osv.osv):

    _name = "vehicle.prev.op"
    _description = "Preventive operations of a vehicle."
    _columns = {
        'name':
        fields.char('REF', size=80, required=True),
        'opdescription':
        fields.text('Description'),
        'vehicle':
        fields.many2one('fleet.vehicles',
                        'Vehicle',
                        required=True,
                        readonly=True),
        'frequency':
        fields.integer('Frequency',
                       help="Estimated time for the next operation."),
        'measUnit':
        fields.selection(
            [('day', 'Days'), ('week', 'Weeks'), ('mon', 'Months'),
             ('year', 'Years')],
            'Meas.',
        ),
        'mileage':
        fields.integer(
            'Op. Mileage Increment',
            help=
            "Mileage increment for the next operation. Measured in kilometers."
        ),
        'lastdate':
        fields.date('Date', help="Last date on which the operation was done."),
        'lastkm':
        fields.integer(
            'Mileage',
            help=
            "Mileage of the vehicle in the last operation. Measured in kilometers."
        ),
        'lasttime':
        fields.time('Time',
                    help="Time it takes to make the operation. hh:mm:ss"),
        'nextkm':
        fields.integer(
            'Mileage',
            help=
            "Mileage of the vehicle for the next operation. Measured in kilometers."
        ),
        'nextdate':
        fields.date('Date', help="Expected date for the next operation."),
        'nexttime':
        fields.time(
            'Time',
            size=10,
            help="Expected time for the execution of the operation. hh:mm:ss"),
        'alert':
        fields.boolean('1st alert', readonly=True),
        'extra_alert':
        fields.boolean('2nd alert', readonly=True),
        'check_al1':
        fields.boolean(
            '1st alert check',
            help=
            "If checked the alarm will be test at the specified parameters."),
        'check_al2':
        fields.boolean(
            '2nd alert check',
            help=
            "If checked the alarm will be test at the specified parameters."),
        'margin_km1':
        fields.integer('Km. Margin', size=20),
        'margin_km2':
        fields.integer('Km. Margin', size=20),
        'margin_fre1':
        fields.integer('Frequency Margin'),
        'measUnit1':
        fields.selection([('day', 'Days'), ('week', 'Weeks'),
                          ('mon', 'Months'), ('year', 'Years')], 'Meas.'),
        'margin_fre2':
        fields.integer('Frequency Margin'),
        'measUnit2':
        fields.selection([('day', 'Days'), ('week', 'Weeks'),
                          ('mon', 'Months'), ('year', 'Years')], 'Meas.'),
        'acdometer':
        fields.related('vehicle',
                       'actodometer',
                       type='integer',
                       relation="fleet.vehicles",
                       string="Actual Odometer"),
    }
    _defaults = {
        #                'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'vehicle.prev.op'),
    }

    def default_get(self, cr, uid, fields, context=None):
        if context is None:
            context = {}
        res = super(vehicle_prev_op, self).default_get(cr, uid, fields,
                                                       context)
        if 'name' in context:
            if context['name']:
                opt = self.pool.get('fleet.vehicles').search(
                    cr, uid, [('name', '=', context['name'])])[0]
                res.update({'vehicle': opt})
        return res
class operation_vehicle_materials(osv.osv):

    _name = 'operation.vehicle.materials'
    _description = 'Operation - Material Relation'

    _columns = {
        'name':
        fields.char('Name', size=64),
        'optype_id':
        fields.many2one('optype', 'Operations'),
        'material':
        fields.one2many('operation.material', 'op_vehi_mat', 'Material'),
        'kms':
        fields.integer('Kms'),
        'op_margin_km1':
        fields.integer('Km. Margin 1'),
        'op_margin_km2':
        fields.integer('Km. Margin 2'),
        'op_frequency':
        fields.integer('Frequency',
                       help="Estimated time for the next operation."),
        'op_measUnit':
        fields.selection([('day', 'Days'), ('week', 'Weeks'),
                          ('mon', 'Months'), ('year', 'Years')], 'Meas.'),
        'op_margin_fre1':
        fields.integer('Frequency Margin 1'),
        'op_measUnit1':
        fields.selection([('day', 'Days'), ('week', 'Weeks'),
                          ('mon', 'Months'), ('year', 'Years')], 'Meas.'),
        'op_margin_fre2':
        fields.integer('Frequency Margin 2'),
        'op_measUnit2':
        fields.selection([('day', 'Days'), ('week', 'Weeks'),
                          ('mon', 'Months'), ('year', 'Years')], 'Meas.'),
        'op_description':
        fields.text('Description'),
        'opmaster':
        fields.many2one('preventive.master', 'Operations'),
        'op_nexttime':
        fields.time('Operation Time'),
    }

    def onchange_opmeasUnit(self, cr, uid, fields, op_measUnit, context={}):
        res = {}
        if op_measUnit:
            res = {
                'op_measUnit1': op_measUnit,
                'op_measUnit2': op_measUnit,
            }
        return {'value': res}

    def onchange_optype_id(self, cr, uid, ids, optype_id, context={}):

        values = {}
        optype_obj = self.pool.get('optype')

        if optype_id != False:
            optype_aux = optype_obj.browse(cr, uid, optype_id)
            values = {
                'kms': optype_aux.km,
                'op_margin_km1': optype_aux.margin_km1,
                'op_margin_km2': optype_aux.margin_km2,
                'op_frequency': optype_aux.frequency,
                'op_measUnit': optype_aux.measUnit,
                'op_margin_fre1': optype_aux.margin_fre1,
                'op_measUnit1': optype_aux.measUnit1,
                'op_margin_fre2': optype_aux.margin_fre2,
                'op_measUnit2': optype_aux.measUnit2,
                'op_description': optype_aux.description,
                'name': optype_aux.name,
                'op_nexttime': optype_aux.nexttime,
            }

        return {'value': values}