!862 增加免租期 和单价计算

Merge pull request !862 from dev_ljm_20241129
This commit is contained in:
ljm
2024-12-20 05:46:54 +00:00
committed by Gitee
2 changed files with 136 additions and 55 deletions
@@ -42,14 +42,26 @@ class PropertyLeaseContract(models.Model):
tax_number = fields.Char(string="税号")
industry = fields.Char(string="行业")
address_for_delivery = fields.Char(string="送达地址")
lease_term = fields.Char(string="租期")
lease_term = fields.Float(string="租期")
lease_term_year = fields.Integer(string="租期")
lease_term_year_uom = fields.Selection([('year', '年')], default="year", readonly=True, string="免租期单位")
lease_term_month = fields.Integer(string="租期")
lease_term_month_uom = fields.Selection([('month', '月')], default="month", readonly=True, string="免租期单位")
term_start_time = fields.Date(string="租期开始时间", default=fields.Datetime.now)
term_end_time = fields.Date(string="租期结束时间")
cycle_dict =fields.Selection([('monthly','月度'), ('quarter','季度'), ('half','半年'),('year','年度')],string='付款方式')
cycle_mode = fields.Selection([('fixed','合同月'), ('floating','自然月')],string='周期方式')
expected_reminders = fields.Char(string="逾期提醒")
increment_method = fields.Selection([('percentage','百分比'),('increment_price','递增单价'),('increment_amount','递增金额')], string='每月递增')
rent_free_period = fields.Datetime(string="免租期")
first_years_begin = fields.Integer(string="第几年开始")
increments_every_few_years = fields.Integer(string="每几年递增")
increment_percentage = fields.Float(string="递增百分比")
increment_price = fields.Float(string="递增单价")
increment_amount = fields.Float(string="递增金额")
rent_free_period = fields.Integer(string="免租期")
rent_free_period_uom = fields.Selection([('year', '年'), ('month', '月')], default="year", string="免租期单位")
breach_time = fields.Date(string="违约计算时点")
percentage_liquidated_damages = fields.Char(string="违约金比例")
date_of_payment = fields.Date(string="每月支付日期")
@@ -83,6 +95,24 @@ class PropertyLeaseContract(models.Model):
contract_time = fields.Date(string="合同签订日期")
handover_time = fields.Date(string="交接日期")
@api.onchange("term_end_time", "term_start_time")
def onchange_term_end_time(self):
for record in self:
if record.term_end_time and record.term_start_time:
delta = relativedelta(record.term_end_time, record.term_start_time)
record.lease_term_year = delta.years
record.lease_term_month = delta.months
@api.onchange("lease_term_year", "lease_term_month")
def onchange_lease_term_year(self):
for record in self:
if record.lease_term_year or record.lease_term_month:
if record.term_start_time:
year = record.lease_term_year if record.lease_term_year else 0
month = record.lease_term_month if record.lease_term_month else 0
months = year * 12 + month
record.term_end_time = record.term_start_time + relativedelta(months=months)
@staticmethod
def divide_time_range_fixed(start_time, end_time, months):
time_ranges = []
@@ -122,29 +152,41 @@ class PropertyLeaseContract(models.Model):
end_date = record.term_end_time
first_years_begin = record.first_years_begin if record.first_years_begin else 0
increments_every_few_years = record.increments_every_few_years
period_rent = record.total_area * record.unit_price # 月租金
monthly_amount = record.total_area * record.unit_price # 月租金
unit_price = record.unit_price # 单价
rent_free_period_month = 0
# 先计算免租期
first_index = 0 # 第几递增周期年
increments_start = start_date # 递增开始
all_period_rent = 0
# 第几年不递增
if first_years_begin:
divided_year_segments = self.divide_time_range_fixed(start_date, end_date, 12)
for segment_year in divided_year_segments:
first_index += 1
if first_years_begin and first_index > first_years_begin:
increments_start = segment_year[0]
break
delta = relativedelta(increments_start, start_date)
months = delta.years * 12 + delta.months
all_period_rent += period_rent * months
if record.rent_free_period and not record.rent_free_period_uom:
raise UserError("请先填写免租期的单位!")
if record.rent_free_period and record.rent_free_period_uom:
if record.rent_free_period_uom == "year":
rent_free_period_month = record.rent_free_period * 12
if record.rent_free_period_uom == "month":
rent_free_period_month = record.rent_free_period
free_start = start_date # 免租期开始
if rent_free_period_month:
free_start = start_date + relativedelta(months=rent_free_period_month)
first_index = 0 # 第几递增周期年
increments_start = free_start # 平稳和递增开始
all_period_rent = 0
if not increments_every_few_years:
delta = relativedelta(end_date, increments_start)
delta = relativedelta(end_date, free_start)
months = delta.years * 12 + delta.months
all_period_rent += period_rent * months
all_period_rent += monthly_amount * months
else:
# 不递增年份的计算
if first_years_begin:
divided_year_segments = self.divide_time_range_fixed(free_start, end_date, 12)
for segment_year in divided_year_segments:
first_index += 1
if first_years_begin and first_index > first_years_begin:
increments_start = segment_year[0]
break
delta = relativedelta(increments_start, free_start)
months = delta.years * 12 + delta.months
all_period_rent = all_period_rent + (monthly_amount * months)
# 开始递增
divided_increments_segments = self.divide_time_range_fixed(increments_start, end_date, increments_every_few_years * 12)
index = 0 # 第几递增周期年
@@ -157,16 +199,14 @@ class PropertyLeaseContract(models.Model):
"""
delta = relativedelta(increments_year[1], increments_year[0])
months = delta.years * 12 + delta.months
if record.increment_price:
if record.increment_method == "increment_price" and record.increment_price:
unit_price = unit_price + record.increment_price
if record.increment_percentage:
period_rent = record.total_area * unit_price * record.increment_percentage
unit_price = period_rent / record.total_area
if record.increment_amount:
period_rent = period_rent + record.increment_amount
unit_price = period_rent / record.total_area
all_period_rent += period_rent * months
monthly_amount = record.total_area * unit_price
if record.increment_method == "percentage" and record.increment_percentage:
monthly_amount = monthly_amount * record.increment_percentage
if record.increment_method == "increment_amount" and record.increment_amount:
monthly_amount = monthly_amount + record.increment_amount
all_period_rent += monthly_amount * months
self.sudo().env["property.rent.list"].create({
"contract_id": record.id,
"contract_code": record.code,
@@ -218,43 +258,67 @@ class PropertyLeaseContract(models.Model):
first_years_begin = record.first_years_begin if record.first_years_begin else 0
increments_every_few_years = record.increments_every_few_years
period_rent = record.total_area * record.unit_price # 月租金
monthly_amount = record.total_area * record.unit_price # 月租金
unit_price = record.unit_price # 单价
rent_free_period_month = 0
# 先计算免租期
first_index = 0 # 第几递增周期年
increments_start = start_date # 递增开始
# 第几年不递增
if record.rent_free_period and not record.rent_free_period_uom:
raise UserError("请先填写免租期的单位!")
if record.rent_free_period and record.rent_free_period_uom:
if record.rent_free_period_uom == "year":
rent_free_period_month = record.rent_free_period * 12
if record.rent_free_period_uom == "month":
rent_free_period_month = record.rent_free_period
free_start = start_date # 免租期开始
if rent_free_period_month:
free_start = start_date + relativedelta(months=rent_free_period_month)
self.sudo().env["property.rent.breakdown.line"].create({
"unit_price": unit_price,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"start_data": start_date,
"end_data": free_start,
"month_number": rent_free_period_month,
"period_rent": 0,
})
# 在计算递增平稳年份租期
increments_start = free_start # 递增开始
# 如果没有递增 那么计算全部
if not increments_every_few_years:
delta = relativedelta(end_date, increments_start)
delta = relativedelta(end_date, free_start)
months = delta.years * 12 + delta.months
self.sudo().env["property.rent.breakdown.line"].create({
"unit_price": unit_price,
"monthly_amount": period_rent,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"start_data": increments_start,
"end_data": end_date,
"month_number": months,
"period_rent": period_rent * months,
"period_rent": monthly_amount * months,
})
# 如果有递增
else:
first_index = 0 # 第几递增周期年
# 有免递增年份的计算
if first_years_begin:
divided_year_segments = self.divide_time_range_fixed(start_date, end_date, 12)
divided_year_segments = self.divide_time_range_fixed(free_start, end_date, 12)
for segment_year in divided_year_segments:
first_index += 1
if first_years_begin and first_index > first_years_begin:
increments_start = segment_year[0]
break
delta = relativedelta(increments_start, start_date)
delta = relativedelta(increments_start, free_start)
months = delta.years * 12 + delta.months
self.sudo().env["property.rent.breakdown.line"].create({
"unit_price": unit_price,
"monthly_amount": period_rent,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"start_data": start_date,
"start_data": free_start,
"end_data": increments_start,
"month_number": months,
"period_rent": period_rent * months,
"period_rent": monthly_amount * months,
})
# 开始递增
@@ -267,25 +331,23 @@ class PropertyLeaseContract(models.Model):
increment_price = fields.Float(string="递增单价")
increment_amount = fields.Float(string="递增金额")
"""
if record.increment_price:
unit_price = unit_price + record.increment_price
if record.increment_percentage:
period_rent = record.total_area * unit_price * record.increment_percentage
unit_price = period_rent / record.total_area
if record.increment_amount:
period_rent = period_rent + record.increment_amount
unit_price = period_rent / record.total_area
delta = relativedelta(increments_year[1], increments_year[0])
months = delta.years * 12 + delta.months
if record.increment_method == "increment_price" and record.increment_price:
unit_price = unit_price + record.increment_price
monthly_amount = record.total_area * unit_price
if record.increment_method == "percentage" and record.increment_percentage:
monthly_amount = monthly_amount * record.increment_percentage
if record.increment_method == "increment_amount" and record.increment_amount:
monthly_amount = monthly_amount + record.increment_amount
self.sudo().env["property.rent.breakdown.line"].create({
"unit_price": unit_price,
"monthly_amount": period_rent,
"monthly_amount": monthly_amount,
"breakdown_id": record.id,
"start_data": increments_year[0],
"end_data": increments_year[1],
"month_number": months,
"period_rent": period_rent * months,
"period_rent": monthly_amount * months,
})
@api.onchange("first_year_rent")
@@ -53,17 +53,36 @@
</group>
<group col="3" string="收费详细">
<group>
<field name="lease_term"/>
<label for="lease_term_year"/>
<div class="d-inline-flex w-100">
<field name="lease_term_year"/>
<field name="lease_term_year_uom" />
<field name="lease_term_month"/>
<field name="lease_term_month_uom" />
</div>
<field name="term_start_time"/>
<field name="term_end_time" />
</group>
<group>
<field name="expected_reminders"/>
<field name="increment_method"/>
<field name="rent_free_period"/>
<field name="increment_percentage" invisible="increment_method != 'percentage'"/>
<field name="increment_price" invisible="increment_method != 'increment_price'"/>
<field name="increment_amount" invisible="increment_method != 'increment_amount'"/>
</group>
<group>
<field name="total_area"/>
<label for="rent_free_period"/>
<div class="d-inline-flex w-100">
<field name="rent_free_period"/>
<field name="rent_free_period_uom" required="rent_free_period"/>
</div>
<field name="first_years_begin"/>
<field name="increments_every_few_years"/>
</group>
<group>
<field name="total_area" />
<field name="cycle_dict"/>
<field name="cycle_mode"/>
</group>