1
This commit is contained in:
@@ -427,10 +427,10 @@ class PropertyLeaseContract(models.Model):
|
||||
monthly_amount = self.total_area * unit_price
|
||||
monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
if self.increment_method == "percentage" and self.increment_value:
|
||||
monthly_amount = monthly_amount * (1 + (self.increment_value / 100))
|
||||
monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
unit_price = monthly_amount / self.total_area
|
||||
unit_price = unit_price * (1 + (self.increment_value / 100))
|
||||
unit_price = float_round(unit_price, precision_digits=2, rounding_method='HALF-UP')
|
||||
monthly_amount = self.total_area * unit_price
|
||||
monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
if self.increment_method == "increment_amount" and self.increment_value:
|
||||
monthly_amount = monthly_amount + self.increment_value
|
||||
monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
@@ -538,209 +538,209 @@ class PropertyLeaseContract(models.Model):
|
||||
|
||||
return all_period_rent
|
||||
|
||||
def do_generate_details_core_1(self, start_date, end_date):
|
||||
"""
|
||||
计算核心算法
|
||||
:return:
|
||||
"""
|
||||
all_period_rent = 0 # 总金额
|
||||
monthly_amount = self.total_area * self.unit_price
|
||||
monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
# 月租金
|
||||
unit_price = self.unit_price # 单价
|
||||
|
||||
# 如果有免租期 月 时间进行到 start_date
|
||||
free_start = start_date
|
||||
if self.rent_free_period_month:
|
||||
free_start = start_date + relativedelta(months=self.rent_free_period_month)
|
||||
if free_start > end_date:
|
||||
free_start = end_date
|
||||
self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
"unit_price": unit_price,
|
||||
"monthly_amount": monthly_amount,
|
||||
"breakdown_id": self.id,
|
||||
"start_data": start_date,
|
||||
"end_data": free_start - relativedelta(days=1),
|
||||
"month_number": self.rent_free_period_month,
|
||||
"period_rent": 0,
|
||||
})]})
|
||||
|
||||
# 如果没有递增 那么计算全部
|
||||
if not self.increments_every_few_years:
|
||||
# 如果免租期有天那么默认增加一个月
|
||||
# 如果有免增期 日
|
||||
free_start_day = free_start
|
||||
if self.rent_free_period_days:
|
||||
free_start_day = free_start + relativedelta(months=self.rent_free_period_days)
|
||||
if free_start_day < end_date:
|
||||
# 计算这个月的天数
|
||||
current_days = calendar.monthrange(free_start.year, free_start.month)[1]
|
||||
current_no_free = (current_days - self.rent_free_period_days) / current_days
|
||||
period_rent = monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0
|
||||
# 计算 免租期天的比值
|
||||
self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
"unit_price": unit_price,
|
||||
"monthly_amount": monthly_amount,
|
||||
"breakdown_id": self.id,
|
||||
"start_data": free_start,
|
||||
"end_data": free_start_day - relativedelta(days=1),
|
||||
"month_number": 1,
|
||||
"period_rent": period_rent,
|
||||
})]})
|
||||
all_period_rent += period_rent
|
||||
|
||||
# 计算 剩余日期的金额
|
||||
if free_start_day < end_date:
|
||||
delta = relativedelta(end_date, free_start_day)
|
||||
months = delta.years * 12 + delta.months
|
||||
free_start_day_end = free_start_day + relativedelta(months=months)
|
||||
self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
"unit_price": unit_price,
|
||||
"monthly_amount": monthly_amount,
|
||||
"breakdown_id": self.id,
|
||||
"start_data": free_start_day,
|
||||
"end_data": free_start_day_end - relativedelta(days=1),
|
||||
"month_number": months,
|
||||
"period_rent": monthly_amount * months,
|
||||
})]})
|
||||
all_period_rent += monthly_amount * months
|
||||
# 说明最后还有几天
|
||||
if delta.days > 0:
|
||||
current_days = calendar.monthrange(free_start_day_end.year, free_start_day_end.month)[1]
|
||||
current_no_free = delta.days / current_days
|
||||
period_rent = monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0
|
||||
# 计算 免租期天的比值
|
||||
self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
"unit_price": unit_price,
|
||||
"monthly_amount": monthly_amount,
|
||||
"breakdown_id": self.id,
|
||||
"start_data": free_start_day_end,
|
||||
"end_data": end_date,
|
||||
"month_number": 1,
|
||||
"period_rent": period_rent,
|
||||
})]})
|
||||
|
||||
# 如果有递增
|
||||
else:
|
||||
first_years_begin_end = start_date
|
||||
# 免递增年份计算
|
||||
if self.first_years_begin > 1:
|
||||
# 免递增结束时间
|
||||
first_years_begin_end = start_date + relativedelta(months=(self.first_years_begin -1) * 12)
|
||||
# 免租期结束时间 free_start
|
||||
# 计算免租期和免增期的差值, 如果免租期超过免增期那么不存在免增期
|
||||
if first_years_begin_end > free_start:
|
||||
# 如果免租期有天那么默认增加一个月
|
||||
if self.rent_free_period_days:
|
||||
# 计算这个月的天数
|
||||
current_days = calendar.monthrange(free_start.year, free_start.month)[1]
|
||||
current_no_free = (current_days - self.rent_free_period_days) / current_days
|
||||
# 计算 免租期天的比值
|
||||
self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
"unit_price": unit_price,
|
||||
"monthly_amount": monthly_amount,
|
||||
"breakdown_id": self.id,
|
||||
"start_data": free_start,
|
||||
"end_data": free_start + relativedelta(months=1) - relativedelta(days=1),
|
||||
"month_number": 1,
|
||||
"period_rent": monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0,
|
||||
})]})
|
||||
new_free_day_amount = monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0
|
||||
all_period_rent += new_free_day_amount
|
||||
# 免租期后退一个月
|
||||
free_start = free_start + relativedelta(months=1)
|
||||
# 计算剩下的免增期
|
||||
delta = relativedelta(first_years_begin_end, free_start)
|
||||
first_months = delta.years * 12 + delta.months
|
||||
self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
"unit_price": unit_price,
|
||||
"monthly_amount": monthly_amount,
|
||||
"breakdown_id": self.id,
|
||||
"start_data": free_start,
|
||||
"end_data": first_years_begin_end - relativedelta(days=1),
|
||||
"month_number": first_months,
|
||||
"period_rent": first_months * monthly_amount,
|
||||
})]})
|
||||
all_period_rent += first_months * monthly_amount
|
||||
# 免增期结束开始递增
|
||||
divided_increments_segments = self.divide_time_range_fixed(first_years_begin_end, end_date, increments_every_few_years*12)
|
||||
year_index = 0 # 第几递增周期年
|
||||
all_months = 0 # 递增的第几个月
|
||||
# 如果免租期 超过 免增期 那么递增期也需要排除
|
||||
if first_years_begin_end < free_start:
|
||||
delta = relativedelta(free_start, first_years_begin_end)
|
||||
free_first_months = delta.years * 12 + delta.months
|
||||
# 如果免租期有天那么默认增加一个月
|
||||
if self.rent_free_period_days:
|
||||
free_first_months = free_first_months + 1
|
||||
else:
|
||||
free_first_months = 0
|
||||
|
||||
for increments_year in divided_increments_segments:
|
||||
year_index += 1
|
||||
"""
|
||||
increment_percentage = fields.Float(string="递增百分比")
|
||||
increment_price = fields.Float(string="递增单价")
|
||||
increment_amount = fields.Float(string="递增金额")
|
||||
"""
|
||||
increments_month = 0
|
||||
# delta = relativedelta(increments_year[1], increments_year[0])
|
||||
# months = delta.years * 12 + delta.months
|
||||
if self.increment_method == "increment_price" and self.increment_value:
|
||||
unit_price = unit_price + self.increment_value
|
||||
monthly_amount = self.total_area * unit_price
|
||||
monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
if self.increment_method == "percentage" and self.increment_value:
|
||||
unit_price = unit_price * (1 + (self.increment_value / 100))
|
||||
monthly_amount = self.total_area * unit_price
|
||||
monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
if self.increment_method == "increment_amount" and self.increment_value:
|
||||
monthly_amount = monthly_amount + self.increment_value
|
||||
monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
unit_price = monthly_amount / self.total_area
|
||||
|
||||
delta = relativedelta(increments_year[1], increments_year[0])
|
||||
months = delta.years * 12 + delta.months
|
||||
month_index = 0
|
||||
# 判断第几月份进入 付费租期
|
||||
for month in range(months):
|
||||
month_index += 1 # 当前第个月
|
||||
# 判断第几月份进入 付费租期
|
||||
all_months += 1
|
||||
if all_months == free_first_months:
|
||||
# 如果免租期有天那么默认增加一个月
|
||||
if self.rent_free_period_days:
|
||||
current_now = increments_year[0] + relativedelta(months=month_index)
|
||||
# 计算这个月的天数
|
||||
current_days = calendar.monthrange(current_now.year, current_now.month)[1]
|
||||
current_no_free = (current_days - self.rent_free_period_days) / current_days
|
||||
# 计算 免租期天的比值
|
||||
self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
"unit_price": unit_price,
|
||||
"monthly_amount": monthly_amount,
|
||||
"breakdown_id": self.id,
|
||||
"start_data": current_now,
|
||||
"end_data": current_now + relativedelta(months=1) - relativedelta(days=1),
|
||||
"month_number": 1,
|
||||
"period_rent": monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0,
|
||||
})]})
|
||||
new_free_day_amount = monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0
|
||||
all_period_rent += new_free_day_amount
|
||||
# 判断是否是免租期
|
||||
if all_months > free_first_months:
|
||||
increments_month += 1
|
||||
if increments_month:
|
||||
self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
"unit_price": unit_price,
|
||||
"monthly_amount": monthly_amount,
|
||||
"breakdown_id": self.id,
|
||||
"start_data": increments_year[1] - relativedelta(months=increments_month),
|
||||
"end_data": increments_year[1] - relativedelta(days=1),
|
||||
"month_number": increments_month,
|
||||
"period_rent": monthly_amount * increments_month,
|
||||
})]})
|
||||
all_period_rent += monthly_amount * increments_month
|
||||
return all_period_rent
|
||||
# def do_generate_details_core_1(self, start_date, end_date):
|
||||
# """
|
||||
# 计算核心算法
|
||||
# :return:
|
||||
# """
|
||||
# all_period_rent = 0 # 总金额
|
||||
# monthly_amount = self.total_area * self.unit_price
|
||||
# monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
# # 月租金
|
||||
# unit_price = self.unit_price # 单价
|
||||
#
|
||||
# # 如果有免租期 月 时间进行到 start_date
|
||||
# free_start = start_date
|
||||
# if self.rent_free_period_month:
|
||||
# free_start = start_date + relativedelta(months=self.rent_free_period_month)
|
||||
# if free_start > end_date:
|
||||
# free_start = end_date
|
||||
# self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
# "unit_price": unit_price,
|
||||
# "monthly_amount": monthly_amount,
|
||||
# "breakdown_id": self.id,
|
||||
# "start_data": start_date,
|
||||
# "end_data": free_start - relativedelta(days=1),
|
||||
# "month_number": self.rent_free_period_month,
|
||||
# "period_rent": 0,
|
||||
# })]})
|
||||
#
|
||||
# # 如果没有递增 那么计算全部
|
||||
# if not self.increments_every_few_years:
|
||||
# # 如果免租期有天那么默认增加一个月
|
||||
# # 如果有免增期 日
|
||||
# free_start_day = free_start
|
||||
# if self.rent_free_period_days:
|
||||
# free_start_day = free_start + relativedelta(months=self.rent_free_period_days)
|
||||
# if free_start_day < end_date:
|
||||
# # 计算这个月的天数
|
||||
# current_days = calendar.monthrange(free_start.year, free_start.month)[1]
|
||||
# current_no_free = (current_days - self.rent_free_period_days) / current_days
|
||||
# period_rent = monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0
|
||||
# # 计算 免租期天的比值
|
||||
# self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
# "unit_price": unit_price,
|
||||
# "monthly_amount": monthly_amount,
|
||||
# "breakdown_id": self.id,
|
||||
# "start_data": free_start,
|
||||
# "end_data": free_start_day - relativedelta(days=1),
|
||||
# "month_number": 1,
|
||||
# "period_rent": period_rent,
|
||||
# })]})
|
||||
# all_period_rent += period_rent
|
||||
#
|
||||
# # 计算 剩余日期的金额
|
||||
# if free_start_day < end_date:
|
||||
# delta = relativedelta(end_date, free_start_day)
|
||||
# months = delta.years * 12 + delta.months
|
||||
# free_start_day_end = free_start_day + relativedelta(months=months)
|
||||
# self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
# "unit_price": unit_price,
|
||||
# "monthly_amount": monthly_amount,
|
||||
# "breakdown_id": self.id,
|
||||
# "start_data": free_start_day,
|
||||
# "end_data": free_start_day_end - relativedelta(days=1),
|
||||
# "month_number": months,
|
||||
# "period_rent": monthly_amount * months,
|
||||
# })]})
|
||||
# all_period_rent += monthly_amount * months
|
||||
# # 说明最后还有几天
|
||||
# if delta.days > 0:
|
||||
# current_days = calendar.monthrange(free_start_day_end.year, free_start_day_end.month)[1]
|
||||
# current_no_free = delta.days / current_days
|
||||
# period_rent = monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0
|
||||
# # 计算 免租期天的比值
|
||||
# self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
# "unit_price": unit_price,
|
||||
# "monthly_amount": monthly_amount,
|
||||
# "breakdown_id": self.id,
|
||||
# "start_data": free_start_day_end,
|
||||
# "end_data": end_date,
|
||||
# "month_number": 1,
|
||||
# "period_rent": period_rent,
|
||||
# })]})
|
||||
#
|
||||
# # 如果有递增
|
||||
# else:
|
||||
# first_years_begin_end = start_date
|
||||
# # 免递增年份计算
|
||||
# if self.first_years_begin > 1:
|
||||
# # 免递增结束时间
|
||||
# first_years_begin_end = start_date + relativedelta(months=(self.first_years_begin -1) * 12)
|
||||
# # 免租期结束时间 free_start
|
||||
# # 计算免租期和免增期的差值, 如果免租期超过免增期那么不存在免增期
|
||||
# if first_years_begin_end > free_start:
|
||||
# # 如果免租期有天那么默认增加一个月
|
||||
# if self.rent_free_period_days:
|
||||
# # 计算这个月的天数
|
||||
# current_days = calendar.monthrange(free_start.year, free_start.month)[1]
|
||||
# current_no_free = (current_days - self.rent_free_period_days) / current_days
|
||||
# # 计算 免租期天的比值
|
||||
# self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
# "unit_price": unit_price,
|
||||
# "monthly_amount": monthly_amount,
|
||||
# "breakdown_id": self.id,
|
||||
# "start_data": free_start,
|
||||
# "end_data": free_start + relativedelta(months=1) - relativedelta(days=1),
|
||||
# "month_number": 1,
|
||||
# "period_rent": monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0,
|
||||
# })]})
|
||||
# new_free_day_amount = monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0
|
||||
# all_period_rent += new_free_day_amount
|
||||
# # 免租期后退一个月
|
||||
# free_start = free_start + relativedelta(months=1)
|
||||
# # 计算剩下的免增期
|
||||
# delta = relativedelta(first_years_begin_end, free_start)
|
||||
# first_months = delta.years * 12 + delta.months
|
||||
# self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
# "unit_price": unit_price,
|
||||
# "monthly_amount": monthly_amount,
|
||||
# "breakdown_id": self.id,
|
||||
# "start_data": free_start,
|
||||
# "end_data": first_years_begin_end - relativedelta(days=1),
|
||||
# "month_number": first_months,
|
||||
# "period_rent": first_months * monthly_amount,
|
||||
# })]})
|
||||
# all_period_rent += first_months * monthly_amount
|
||||
# # 免增期结束开始递增
|
||||
# divided_increments_segments = self.divide_time_range_fixed(first_years_begin_end, end_date, increments_every_few_years*12)
|
||||
# year_index = 0 # 第几递增周期年
|
||||
# all_months = 0 # 递增的第几个月
|
||||
# # 如果免租期 超过 免增期 那么递增期也需要排除
|
||||
# if first_years_begin_end < free_start:
|
||||
# delta = relativedelta(free_start, first_years_begin_end)
|
||||
# free_first_months = delta.years * 12 + delta.months
|
||||
# # 如果免租期有天那么默认增加一个月
|
||||
# if self.rent_free_period_days:
|
||||
# free_first_months = free_first_months + 1
|
||||
# else:
|
||||
# free_first_months = 0
|
||||
#
|
||||
# for increments_year in divided_increments_segments:
|
||||
# year_index += 1
|
||||
# """
|
||||
# increment_percentage = fields.Float(string="递增百分比")
|
||||
# increment_price = fields.Float(string="递增单价")
|
||||
# increment_amount = fields.Float(string="递增金额")
|
||||
# """
|
||||
# increments_month = 0
|
||||
# # delta = relativedelta(increments_year[1], increments_year[0])
|
||||
# # months = delta.years * 12 + delta.months
|
||||
# if self.increment_method == "increment_price" and self.increment_value:
|
||||
# unit_price = unit_price + self.increment_value
|
||||
# monthly_amount = self.total_area * unit_price
|
||||
# monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
# if self.increment_method == "percentage" and self.increment_value:
|
||||
# unit_price = unit_price * (1 + (self.increment_value / 100))
|
||||
# monthly_amount = self.total_area * unit_price
|
||||
# monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
# if self.increment_method == "increment_amount" and self.increment_value:
|
||||
# monthly_amount = monthly_amount + self.increment_value
|
||||
# monthly_amount = float_round(monthly_amount, precision_digits=0, rounding_method='HALF-UP') # 月租金
|
||||
# unit_price = monthly_amount / self.total_area
|
||||
#
|
||||
# delta = relativedelta(increments_year[1], increments_year[0])
|
||||
# months = delta.years * 12 + delta.months
|
||||
# month_index = 0
|
||||
# # 判断第几月份进入 付费租期
|
||||
# for month in range(months):
|
||||
# month_index += 1 # 当前第个月
|
||||
# # 判断第几月份进入 付费租期
|
||||
# all_months += 1
|
||||
# if all_months == free_first_months:
|
||||
# # 如果免租期有天那么默认增加一个月
|
||||
# if self.rent_free_period_days:
|
||||
# current_now = increments_year[0] + relativedelta(months=month_index)
|
||||
# # 计算这个月的天数
|
||||
# current_days = calendar.monthrange(current_now.year, current_now.month)[1]
|
||||
# current_no_free = (current_days - self.rent_free_period_days) / current_days
|
||||
# # 计算 免租期天的比值
|
||||
# self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
# "unit_price": unit_price,
|
||||
# "monthly_amount": monthly_amount,
|
||||
# "breakdown_id": self.id,
|
||||
# "start_data": current_now,
|
||||
# "end_data": current_now + relativedelta(months=1) - relativedelta(days=1),
|
||||
# "month_number": 1,
|
||||
# "period_rent": monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0,
|
||||
# })]})
|
||||
# new_free_day_amount = monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0
|
||||
# all_period_rent += new_free_day_amount
|
||||
# # 判断是否是免租期
|
||||
# if all_months > free_first_months:
|
||||
# increments_month += 1
|
||||
# if increments_month:
|
||||
# self.sudo().write({'breakdown_ids': [(0, 0, {
|
||||
# "unit_price": unit_price,
|
||||
# "monthly_amount": monthly_amount,
|
||||
# "breakdown_id": self.id,
|
||||
# "start_data": increments_year[1] - relativedelta(months=increments_month),
|
||||
# "end_data": increments_year[1] - relativedelta(days=1),
|
||||
# "month_number": increments_month,
|
||||
# "period_rent": monthly_amount * increments_month,
|
||||
# })]})
|
||||
# all_period_rent += monthly_amount * increments_month
|
||||
# return all_period_rent
|
||||
|
||||
# @api.onchange("first_year_rent")
|
||||
# def _onchange_first_year_rent(self):
|
||||
|
||||
Reference in New Issue
Block a user