def re_calculate_fee(self,cr,uid,context): """ 重新计算应退费用 :params context 包含计算上下问信息,required :params context[room_id] integer 包厢id,required """ #计算以往客户付费合计 pool = self.pool room_id = context.get('room_id') room = pool.get('ktv.room').browse(cr,uid,room_id) r_op = room.current_room_operate_id sum_refund_info = self.get_default_checkout_dict(cr,uid) #在实际消费时长 < 买钟时长(不包括赠送时长)时,可以退钟 #计算退钟时间,退钟时长 = refund_minutes = ktv_helper.str_timedelta_minutes(ktv_helper.utc_now_str(),r_op.close_time) - r_op.present_minutes _logger.debug("refund_minutes = % s" % refund_minutes) if refund_minutes <= 0: return None #计算room_operate.close_time ~ datetime.now()时间内应收费用(折前) tmp_dict = {k:v for k,v in context.items() if k not in ('member_id','discount_card_id','discounter_id')} tmp_dict['price_class_id'] = getattr(r_op.price_class_id,'id') tmp_dict['consume_minutes'] = refund_minutes sum_refund_info = self.calculate_sum_pay_info(cr,uid,tmp_dict) #退钟时,open_time = now close_time = close_time - refund_minutes sum_refund_info['open_time'] = ktv_helper.utc_now_str() sum_refund_info['close_time'] = ktv_helper.strftime(datetime.now() + timedelta(minutes = refund_minutes)) self.set_calculate_fields(cr,uid,sum_refund_info) return sum_refund_info
def update_previous_checkout_for_presale_room_change(self,cr,uid,op_id): """ 修改上次结账信息的关房时间和消费时间,在预售换房时使用 :param op_id integer :rtype dict 更新的checkout """ #修改关联的最后一次结账信息中的关闭时间和消费时长 pool = self.pool p_checkout,l_checkout = self.last_two_presale_checkout(cr,uid,op_id) close_time = ktv_helper.utc_now_str() consume_minutes = ktv_helper.str_timedelta_minutes(p_checkout['open_time'],close_time) osv_name = p_checkout['osv_name'] update_attrs = {"close_time" : close_time} if 'room_change' in osv_name: update_attrs['changed_room_minutes'] = consume_minutes else: update_attrs['consume_minutes'] = consume_minutes if p_checkout: pool.get(osv_name).write(cr,uid,p_checkout['id'],update_attrs) return p_checkout and pool.get(osv_name).read(cr,uid,p_checkout['id'])
def re_calculate_fee(self, cr, uid, context): """ 重新计算应退费用 :params context 包含计算上下问信息,required :params context[room_id] integer 包厢id,required """ #计算以往客户付费合计 pool = self.pool room_id = context.get('room_id') room = pool.get('ktv.room').browse(cr, uid, room_id) r_op = room.current_room_operate_id sum_refund_info = self.get_default_checkout_dict(cr, uid) #在实际消费时长 < 买钟时长(不包括赠送时长)时,可以退钟 #计算退钟时间,退钟时长 = refund_minutes = ktv_helper.str_timedelta_minutes( ktv_helper.utc_now_str(), r_op.close_time) - r_op.present_minutes _logger.debug("refund_minutes = % s" % refund_minutes) if refund_minutes <= 0: return None #计算room_operate.close_time ~ datetime.now()时间内应收费用(折前) tmp_dict = { k: v for k, v in context.items() if k not in ('member_id', 'discount_card_id', 'discounter_id') } tmp_dict['price_class_id'] = getattr(r_op.price_class_id, 'id') tmp_dict['consume_minutes'] = refund_minutes sum_refund_info = self.calculate_sum_pay_info(cr, uid, tmp_dict) #退钟时,open_time = now close_time = close_time - refund_minutes sum_refund_info['open_time'] = ktv_helper.utc_now_str() sum_refund_info['close_time'] = ktv_helper.strftime( datetime.now() + timedelta(minutes=refund_minutes)) self.set_calculate_fields(cr, uid, sum_refund_info) return sum_refund_info
def update_previous_checkout_for_presale_room_change(self, cr, uid, op_id): """ 修改上次结账信息的关房时间和消费时间,在预售换房时使用 :param op_id integer :rtype dict 更新的checkout """ #修改关联的最后一次结账信息中的关闭时间和消费时长 pool = self.pool p_checkout, l_checkout = self.last_two_presale_checkout(cr, uid, op_id) close_time = ktv_helper.utc_now_str() consume_minutes = ktv_helper.str_timedelta_minutes( p_checkout['open_time'], close_time) osv_name = p_checkout['osv_name'] update_attrs = {"close_time": close_time} if 'room_change' in osv_name: update_attrs['changed_room_minutes'] = consume_minutes else: update_attrs['consume_minutes'] = consume_minutes if p_checkout: pool.get(osv_name).write(cr, uid, p_checkout['id'], update_attrs) return p_checkout and pool.get(osv_name).read(cr, uid, p_checkout['id'])
def _compute_fields(self,cr,uid,ids,name,args,context = None): """ 计算以下字段的值: open_time 以room_opens或room_checkout_buytime或room_checkout_buytime中的open_time为准 close_time 以最后一次结算时间为准 consume_minutes changed_room_minutes """ ret = {} for record in self.browse(cr,uid,ids): #依次判断所有开房相关操作:room_opens > room_checkout_buyout > room_checkout_buytime which_room_open_ops = record.room_opens_ids or record.room_checkout_buyout_ids or record.room_checkout_buytime_ids last_room = which_room_open_ops[0].room_id if which_room_open_ops else None fee_type_id = which_room_open_ops[0].fee_type_id.id if which_room_open_ops else None price_class_id = which_room_open_ops[0].price_class_id.id if which_room_open_ops else None open_time = which_room_open_ops[0].open_time if which_room_open_ops else None guest_name = which_room_open_ops[0].guest_name if which_room_open_ops else None persons_count = which_room_open_ops[0].persons_count if which_room_open_ops else None prepay_fee = which_room_open_ops[0].prepay_fee if which_room_open_ops else None #判断是否预售操作presale is_presale = True if record.room_checkout_buyout_ids or record.room_checkout_buytime_ids else False #是否已结账 is_shift_reported = True if record.casher_shift_report_id else False #依次判断关房操作,也有可能当前包厢尚未关闭,close_time可能为空 #room_change > room_checkout > room_change_checkout_buytime > room_change_checkout_buyout > room_checkout_buytime which_room_close_ops = record.room_checkout_ids or record.room_change_ids or \ record.room_change_checkout_buyout_ids or record.room_checkout_buyout_ids or \ record.room_checkout_buytime_refund_ids or record.room_checkout_buytime_continue_ids or \ record.room_change_checkout_buytime_ids or record.room_checkout_buytime_ids close_time = None last_member = None last_buyout_config = None last_cron = None if which_room_close_ops: close_time = which_room_close_ops[0].close_time #获取最后一次操作的member_id last_member =getattr(which_room_close_ops[-1],'member_id',None) last_buyout_config = getattr(which_room_close_ops[-1],'buyout_config_id',None) #最后一次cron任务 last_cron = getattr(which_room_close_ops[-1],'cron_id',None) #获取last_room_id last_room = getattr(which_room_close_ops[-1],'room_id',None) if not last_buyout_config: #最后买断id last_buyout_config = getattr(which_room_open_ops[0],'buyout_config_id',None) if which_room_open_ops else None last_buyout_config_id = getattr(last_buyout_config,'id',None) last_cron_id = getattr(last_cron,'id',None) last_room_id = getattr(last_room,'id',None) if not last_member: last_member = which_room_open_ops[0].member_id if which_room_open_ops else None last_member_id = getattr(last_member,'id',None) consume_minutes = 0 if open_time: consume_minutes = ktv_helper.str_timedelta_minutes(open_time,close_time if close_time else ktv_helper.utc_now_str()) #到钟报警 alert = False #计算已消费时长和剩余消费时长 left_minutes = 0 #如果当前时间>close_time 则该包厢已关闭 #如果当前时间<=close_time 则该包厢尚未关闭 if close_time: if ktv_helper.utc_now_str() > close_time: left_minutes = 0 else: left_minutes = ktv_helper.str_timedelta_minutes(ktv_helper.utc_now_str(),close_time) if left_minutes <= 5: alert = True #计算consume_minutes ori_consume_minutes = changed_room_minutes = total_minutes = present_minutes = song_ticket_minutes = 0 total_fee = room_fee = hourly_fee = changed_room_fee = changed_room_hourly_fee = guest_damage_fee = total_discount_fee = total_after_discount_fee = total_after_discount_cash_fee = 0.0 on_credit_fee = member_card_fee = credit_card_fee = sales_voucher_fee = free_fee = 0.0 for r_ops in (record.room_checkout_ids,record.room_checkout_buyout_ids,record.room_checkout_buytime_ids,record.room_change_checkout_buyout_ids,record.room_change_checkout_buytime_ids,record.room_checkout_buytime_continue_ids): for r_op in r_ops: present_minutes += r_op.present_minutes changed_room_minutes += r_op.changed_room_minutes ori_consume_minutes += r_op.consume_minutes song_ticket_minutes += r_op.song_ticket_minutes room_fee += r_op.room_fee hourly_fee += r_op.hourly_fee changed_room_fee += r_op.changed_room_fee changed_room_hourly_fee += r_op.changed_room_hourly_fee guest_damage_fee += r_op.guest_damage_fee member_card_fee += r_op.member_card_fee credit_card_fee += r_op.credit_card_fee on_credit_fee += r_op.on_credit_fee sales_voucher_fee += r_op.sales_voucher_fee free_fee += r_op.free_fee total_fee += r_op.total_fee total_discount_fee += r_op.total_discount_fee total_after_discount_fee += r_op.total_after_discount_fee total_after_discount_cash_fee += r_op.total_after_discount_cash_fee total_minutes += r_op.consume_minutes + r_op.changed_room_minutes ret[record.id] = { 'guest_name' : guest_name, 'persons_count' : persons_count or 1, 'fee_type_id' : fee_type_id, 'price_class_id' : price_class_id, 'last_cron_id' : last_cron_id, 'last_room_id' : last_room_id, 'last_member_id' : last_member_id, 'last_buyout_config_id' : last_buyout_config_id, 'open_time' : open_time, 'close_time' : close_time, 'prepay_fee' : prepay_fee or 0.0, 'ori_consume_minutes' : ori_consume_minutes or 0, 'consume_minutes' : consume_minutes or 0, 'left_minutes' : left_minutes or 0, 'alert' : alert, 'present_minutes' : present_minutes or 0, 'total_minutes' : total_minutes or 0, 'room_fee' : room_fee or 0.0, 'hourly_fee' : hourly_fee or 0.0, 'changed_room_fee' : changed_room_fee or 0.0, 'changed_room_hourly_fee' : changed_room_hourly_fee or 0.0, 'changed_room_minutes' : changed_room_minutes or 0, 'guest_damage_fee' : guest_damage_fee or 0.0, 'member_card_fee' : member_card_fee or 0.0, 'credit_card_fee' : credit_card_fee or 0.0, 'sales_voucher_fee' : sales_voucher_fee or 0.0, 'on_credit_fee' : on_credit_fee or 0.0, 'free_fee' : free_fee or 0.0, 'song_ticket_minutes' : song_ticket_minutes or 0, 'total_fee' : total_fee or 0.0, 'total_discount_fee' : total_discount_fee or 0.0, 'total_after_discount_fee' : total_after_discount_fee or 0.0, 'total_after_discount_cash_fee' : total_after_discount_cash_fee or 0.0, 'is_shift_reported' : is_shift_reported, 'is_presale' : is_presale, } _logger.debug("ret = %s" % ret) return ret
def _compute_fields(self, cr, uid, ids, name, args, context=None): """ 计算以下字段的值: open_time 以room_opens或room_checkout_buytime或room_checkout_buytime中的open_time为准 close_time 以最后一次结算时间为准 consume_minutes changed_room_minutes """ ret = {} for record in self.browse(cr, uid, ids): #依次判断所有开房相关操作:room_opens > room_checkout_buyout > room_checkout_buytime which_room_open_ops = record.room_opens_ids or record.room_checkout_buyout_ids or record.room_checkout_buytime_ids last_room = which_room_open_ops[ 0].room_id if which_room_open_ops else None fee_type_id = which_room_open_ops[ 0].fee_type_id.id if which_room_open_ops else None price_class_id = which_room_open_ops[ 0].price_class_id.id if which_room_open_ops else None open_time = which_room_open_ops[ 0].open_time if which_room_open_ops else None guest_name = which_room_open_ops[ 0].guest_name if which_room_open_ops else None persons_count = which_room_open_ops[ 0].persons_count if which_room_open_ops else None prepay_fee = which_room_open_ops[ 0].prepay_fee if which_room_open_ops else None #判断是否预售操作presale is_presale = True if record.room_checkout_buyout_ids or record.room_checkout_buytime_ids else False #是否已结账 is_shift_reported = True if record.casher_shift_report_id else False #依次判断关房操作,也有可能当前包厢尚未关闭,close_time可能为空 #room_change > room_checkout > room_change_checkout_buytime > room_change_checkout_buyout > room_checkout_buytime which_room_close_ops = record.room_checkout_ids or record.room_change_ids or \ record.room_change_checkout_buyout_ids or record.room_checkout_buyout_ids or \ record.room_checkout_buytime_refund_ids or record.room_checkout_buytime_continue_ids or \ record.room_change_checkout_buytime_ids or record.room_checkout_buytime_ids close_time = None last_member = None last_buyout_config = None last_cron = None if which_room_close_ops: close_time = which_room_close_ops[0].close_time #获取最后一次操作的member_id last_member = getattr(which_room_close_ops[-1], 'member_id', None) last_buyout_config = getattr(which_room_close_ops[-1], 'buyout_config_id', None) #最后一次cron任务 last_cron = getattr(which_room_close_ops[-1], 'cron_id', None) #获取last_room_id last_room = getattr(which_room_close_ops[-1], 'room_id', None) if not last_buyout_config: #最后买断id last_buyout_config = getattr( which_room_open_ops[0], 'buyout_config_id', None) if which_room_open_ops else None last_buyout_config_id = getattr(last_buyout_config, 'id', None) last_cron_id = getattr(last_cron, 'id', None) last_room_id = getattr(last_room, 'id', None) if not last_member: last_member = which_room_open_ops[ 0].member_id if which_room_open_ops else None last_member_id = getattr(last_member, 'id', None) consume_minutes = 0 if open_time: consume_minutes = ktv_helper.str_timedelta_minutes( open_time, close_time if close_time else ktv_helper.utc_now_str()) #到钟报警 alert = False #计算已消费时长和剩余消费时长 left_minutes = 0 #如果当前时间>close_time 则该包厢已关闭 #如果当前时间<=close_time 则该包厢尚未关闭 if close_time: if ktv_helper.utc_now_str() > close_time: left_minutes = 0 else: left_minutes = ktv_helper.str_timedelta_minutes( ktv_helper.utc_now_str(), close_time) if left_minutes <= 5: alert = True #计算consume_minutes ori_consume_minutes = changed_room_minutes = total_minutes = present_minutes = song_ticket_minutes = 0 total_fee = room_fee = hourly_fee = changed_room_fee = changed_room_hourly_fee = guest_damage_fee = total_discount_fee = total_after_discount_fee = total_after_discount_cash_fee = 0.0 on_credit_fee = member_card_fee = credit_card_fee = sales_voucher_fee = free_fee = 0.0 for r_ops in (record.room_checkout_ids, record.room_checkout_buyout_ids, record.room_checkout_buytime_ids, record.room_change_checkout_buyout_ids, record.room_change_checkout_buytime_ids, record.room_checkout_buytime_continue_ids): for r_op in r_ops: present_minutes += r_op.present_minutes changed_room_minutes += r_op.changed_room_minutes ori_consume_minutes += r_op.consume_minutes song_ticket_minutes += r_op.song_ticket_minutes room_fee += r_op.room_fee hourly_fee += r_op.hourly_fee changed_room_fee += r_op.changed_room_fee changed_room_hourly_fee += r_op.changed_room_hourly_fee guest_damage_fee += r_op.guest_damage_fee member_card_fee += r_op.member_card_fee credit_card_fee += r_op.credit_card_fee on_credit_fee += r_op.on_credit_fee sales_voucher_fee += r_op.sales_voucher_fee free_fee += r_op.free_fee total_fee += r_op.total_fee total_discount_fee += r_op.total_discount_fee total_after_discount_fee += r_op.total_after_discount_fee total_after_discount_cash_fee += r_op.total_after_discount_cash_fee total_minutes += r_op.consume_minutes + r_op.changed_room_minutes ret[record.id] = { 'guest_name': guest_name, 'persons_count': persons_count or 1, 'fee_type_id': fee_type_id, 'price_class_id': price_class_id, 'last_cron_id': last_cron_id, 'last_room_id': last_room_id, 'last_member_id': last_member_id, 'last_buyout_config_id': last_buyout_config_id, 'open_time': open_time, 'close_time': close_time, 'prepay_fee': prepay_fee or 0.0, 'ori_consume_minutes': ori_consume_minutes or 0, 'consume_minutes': consume_minutes or 0, 'left_minutes': left_minutes or 0, 'alert': alert, 'present_minutes': present_minutes or 0, 'total_minutes': total_minutes or 0, 'room_fee': room_fee or 0.0, 'hourly_fee': hourly_fee or 0.0, 'changed_room_fee': changed_room_fee or 0.0, 'changed_room_hourly_fee': changed_room_hourly_fee or 0.0, 'changed_room_minutes': changed_room_minutes or 0, 'guest_damage_fee': guest_damage_fee or 0.0, 'member_card_fee': member_card_fee or 0.0, 'credit_card_fee': credit_card_fee or 0.0, 'sales_voucher_fee': sales_voucher_fee or 0.0, 'on_credit_fee': on_credit_fee or 0.0, 'free_fee': free_fee or 0.0, 'song_ticket_minutes': song_ticket_minutes or 0, 'total_fee': total_fee or 0.0, 'total_discount_fee': total_discount_fee or 0.0, 'total_after_discount_fee': total_after_discount_fee or 0.0, 'total_after_discount_cash_fee': total_after_discount_cash_fee or 0.0, 'is_shift_reported': is_shift_reported, 'is_presale': is_presale, } _logger.debug("ret = %s" % ret) return ret