Merge pull request !1167 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2025-01-06 13:10:53 +00:00
committed by Gitee
2 changed files with 50 additions and 47 deletions
@@ -328,27 +328,27 @@ class PropertyLeaseContract(models.Model):
record.do_generate_details_core(start_date, end_date)
def do_generate_details_core(record, start_date, end_date):
def do_generate_details_core(self, start_date, end_date):
"""
计算核心算法
:return:
"""
all_period_rent = 0
first_years_begin = record.first_years_begin if record.first_years_begin else 0
increments_every_few_years = record.increments_every_few_years
monthly_amount = record.total_area * record.unit_price # 月租金
unit_price = record.unit_price # 单价
first_years_begin = self.first_years_begin if self.first_years_begin else 0
increments_every_few_years = self.increments_every_few_years
monthly_amount = self.total_area * self.unit_price # 月租金
unit_price = self.unit_price # 单价
rent_free_period_month = 0
if record.rent_free_period_month:
rent_free_period_month += record.rent_free_period_month
if self.rent_free_period_month:
rent_free_period_month += self.rent_free_period_month
free_start = start_date # 免租期开始
if rent_free_period_month:
free_start = start_date + relativedelta(months=rent_free_period_month)
record.sudo().write({'breakdown_ids': [(0, 0, {
self.sudo().write({'breakdown_ids': [(0, 0, {
"unit_price": unit_price,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"breakdown_id": self.id,
"start_data": start_date,
"end_data": free_start - relativedelta(days=1),
"month_number": rent_free_period_month,
@@ -357,31 +357,32 @@ class PropertyLeaseContract(models.Model):
# 如果没有递增 那么计算全部
if not increments_every_few_years:
# 如果免租期有天那么默认增加一个月
if record.rent_free_period_days:
if self.rent_free_period_days:
# 计算这个月的天数
current_days = calendar.monthrange(free_start.year, free_start.month)[1]
current_no_free = (current_days - record.rent_free_period_days) / current_days
current_no_free = (current_days - self.rent_free_period_days) / current_days
# 计算 免租期天的比值
record.sudo().write({'breakdown_ids': [(0, 0, {
self.sudo().write({'breakdown_ids': [(0, 0, {
"unit_price": unit_price,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"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,
"period_rent": monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0,
})]})
all_period_rent += monthly_amount * 1 * current_no_free
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(end_date, free_start)
months = delta.years * 12 + delta.months
record.sudo().write({'breakdown_ids': [(0, 0, {
self.sudo().write({'breakdown_ids': [(0, 0, {
"unit_price": unit_price,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"breakdown_id": self.id,
"start_data": free_start,
"end_data": end_date - relativedelta(days=1),
"month_number": months,
@@ -399,30 +400,31 @@ class PropertyLeaseContract(models.Model):
# 计算免租期和免增期的差值, 如果免租期超过免增期那么不存在免增期
if first_years_begin_end > free_start:
# 如果免租期有天那么默认增加一个月
if record.rent_free_period_days:
if self.rent_free_period_days:
# 计算这个月的天数
current_days = calendar.monthrange(free_start.year, free_start.month)[1]
current_no_free = (current_days - record.rent_free_period_days) / current_days
current_no_free = (current_days - self.rent_free_period_days) / current_days
# 计算 免租期天的比值
record.sudo().write({'breakdown_ids': [(0, 0, {
self.sudo().write({'breakdown_ids': [(0, 0, {
"unit_price": unit_price,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"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,
"period_rent": monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0,
})]})
all_period_rent += monthly_amount * 1 * current_no_free
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
record.sudo().write({'breakdown_ids': [(0, 0, {
self.sudo().write({'breakdown_ids': [(0, 0, {
"unit_price": unit_price,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"breakdown_id": self.id,
"start_data": free_start,
"end_data": first_years_begin_end,
"month_number": first_months,
@@ -430,15 +432,15 @@ class PropertyLeaseContract(models.Model):
})]})
all_period_rent += first_months * monthly_amount
# 免增期结束开始递增
divided_increments_segments = record.divide_time_range_fixed(first_years_begin_end, end_date, increments_every_few_years*12)
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(first_years_begin_end, free_start)
delta = relativedelta(free_start, first_years_begin_end)
free_first_months = delta.years * 12 + delta.months
# 如果免租期有天那么默认增加一个月
if record.rent_free_period_days:
if self.rent_free_period_days:
free_first_months = free_first_months + 1
else:
free_first_months = 0
@@ -453,15 +455,15 @@ class PropertyLeaseContract(models.Model):
increments_month = 0
# delta = relativedelta(increments_year[1], increments_year[0])
# months = delta.years * 12 + delta.months
if record.increment_method == "increment_price" and record.increment_value:
unit_price = unit_price + record.increment_value
monthly_amount = record.total_area * unit_price
if record.increment_method == "percentage" and record.increment_value:
monthly_amount = monthly_amount * record.increment_value
unit_price = monthly_amount / record.total_area
if record.increment_method == "increment_amount" and record.increment_value:
monthly_amount = monthly_amount + record.increment_value
unit_price = monthly_amount / record.total_area
if self.increment_method == "increment_price" and self.increment_value:
unit_price = unit_price + self.increment_value
monthly_amount = self.total_area * unit_price
if self.increment_method == "percentage" and self.increment_value:
monthly_amount = monthly_amount * self.increment_value
unit_price = monthly_amount / self.total_area
if self.increment_method == "increment_amount" and self.increment_value:
monthly_amount = monthly_amount + self.increment_value
unit_price = monthly_amount / self.total_area
delta = relativedelta(increments_year[1], increments_year[0])
months = delta.years * 12 + delta.months
@@ -473,30 +475,31 @@ class PropertyLeaseContract(models.Model):
all_months += 1
if all_months == free_first_months:
# 如果免租期有天那么默认增加一个月
if record.rent_free_period_days:
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 - record.rent_free_period_days) / current_days
current_no_free = (current_days - self.rent_free_period_days) / current_days
# 计算 免租期天的比值
record.sudo().write({'breakdown_ids': [(0, 0, {
self.sudo().write({'breakdown_ids': [(0, 0, {
"unit_price": unit_price,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"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,
"period_rent": monthly_amount * 1 * current_no_free if monthly_amount * 1 * current_no_free > 0 else 0,
})]})
all_period_rent += monthly_amount * 1 * current_no_free
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:
record.sudo().write({'breakdown_ids': [(0, 0, {
self.sudo().write({'breakdown_ids': [(0, 0, {
"unit_price": unit_price,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"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,
@@ -80,7 +80,7 @@
<field name="breakdown_ids" string=" ">
<tree editable="bottom">
<field name="breakdown_id" column_invisible="1"/>
<field name="charges"/>
<!-- <field name="charges"/>-->
<field name="unit_price"/>
<field name="monthly_amount"/>
<field name="start_data"/>
@@ -346,7 +346,7 @@
<field name="breakdown_ids" string=" ">
<tree editable="bottom">
<field name="breakdown_id" column_invisible="1"/>
<field name="charges"/>
<!-- <field name="charges"/>-->
<field name="unit_price"/>
<field name="monthly_amount"/>
<field name="start_data"/>