def calculate_prorated_price(self, line): """ Calculate line price using prorata """ start_date = date_helper.convert_to_date(line.subscription_start_date) end_date = date_helper.convert_to_date(line.subscription_end_date) #First case -> same month if start_date.month == end_date.month: last_day = date_helper.get_last_day_month(end_date) #Normal case : 1 to end of month if start_date.day == 1 : if end_date.day == last_day.day: return line.price_unit #TODO : pay less if cancelled < 1 month ? else: return line.price_unit else: #We should never be there return line.price_unit #Second case -> more than 1 month else: difference = (end_date - start_date).days #If its more than 1 month of difference, we modify the price if difference > 31: pro_rated_days = difference - 31 pro_rated_price = line.price_unit / 31 total = line.price_unit + round(pro_rated_price * pro_rated_days) return total else: return line.price_unit return line.price_unit
def calculate_prorated_price(self, line): """ Calculate line price using prorata """ start_date = date_helper.convert_to_date(line.subscription_start_date) end_date = date_helper.convert_to_date(line.subscription_end_date) #First case -> same month if start_date.month == end_date.month: last_day = date_helper.get_last_day_month(end_date) #Normal case : 1 to end of month if start_date.day == 1: if end_date.day == last_day.day: return line.price_unit #TODO : pay less if cancelled < 1 month ? else: return line.price_unit else: #We should never be there return line.price_unit #Second case -> more than 1 month else: difference = (end_date - start_date).days #If its more than 1 month of difference, we modify the price if difference > 31: pro_rated_days = difference - 31 pro_rated_price = line.price_unit / 31 total = line.price_unit + round( pro_rated_price * pro_rated_days) return total else: return line.price_unit return line.price_unit
def onchange_start_date(self, cr, uid, ids, subscription_start_date): """ Automatically set the subscription end date to the end of the month of subscription_start_date """ values = {} today = date.today() parsed_start_date = date_helper.convert_to_date(subscription_start_date) #remove this test if subscription_start_date: #new_end_date = date_helper.get_last_day_month(parsed_start_date) if parsed_start_date.day > 14: new_end_date = date_helper.get_last_day_next_month(today) else: new_end_date = date_helper.get_last_day_month(today) values['subscription_end_date'] = str(new_end_date.strftime("%Y-%m-%d")) return {'value': values}
def onchange_start_date(self, cr, uid, ids, subscription_start_date): """ Automatically set the subscription end date to the end of the month of subscription_start_date """ values = {} today = date.today() parsed_start_date = date_helper.convert_to_date( subscription_start_date) #remove this test if subscription_start_date: #new_end_date = date_helper.get_last_day_month(parsed_start_date) if parsed_start_date.day > 14: new_end_date = date_helper.get_last_day_next_month(today) else: new_end_date = date_helper.get_last_day_month(today) values['subscription_end_date'] = str( new_end_date.strftime("%Y-%m-%d")) return {'value': values}