From 13da0a5b082691cd89b831ff9078199b7cbcf39a Mon Sep 17 00:00:00 2001
From: ljmwkx <1340053001@qq.com>
Date: Fri, 20 Dec 2024 12:50:47 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E7=89=A9=E4=B8=9A=20=E8=AE=A1=E7=AE=97?=
=?UTF-8?q?=E9=80=BB=E8=BE=91=E5=A2=9E=E5=8A=A0=E5=85=8D=E7=A7=9F=E6=9C=9F?=
=?UTF-8?q?=20=E8=AE=A1=E7=AE=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../models/property_lease_contract.py | 138 +++++++++++-------
.../views/property_lease_contract.xml | 21 ++-
2 files changed, 100 insertions(+), 59 deletions(-)
diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py
index 18eaf3edf..f9a6c5a5e 100644
--- a/yuthon_property_approval/models/property_lease_contract.py
+++ b/yuthon_property_approval/models/property_lease_contract.py
@@ -42,7 +42,8 @@ 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.Integer(string="租期")
+ lease_term_uom = fields.Selection([('year', '年'), ('month', '月')], default="year", 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='付款方式')
@@ -56,7 +57,8 @@ class PropertyLeaseContract(models.Model):
increment_percentage = fields.Float(string="递增百分比")
increment_price = fields.Float(string="递增单价")
increment_amount = fields.Float(string="递增金额")
- rent_free_period = fields.Char(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="每月支付日期")
@@ -132,29 +134,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 # 第几递增周期年
@@ -167,16 +181,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,
@@ -228,43 +240,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,
})
# 开始递增
@@ -277,25 +313,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,
})
class PropertyLeaseContractLine(models.Model):
diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml
index a1dfa9031..25710ce44 100644
--- a/yuthon_property_approval/views/property_lease_contract.xml
+++ b/yuthon_property_approval/views/property_lease_contract.xml
@@ -53,21 +53,28 @@
-
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
From e48deb153b82d900f6b70ccf4292674048b84109 Mon Sep 17 00:00:00 2001
From: ljmwkx <1340053001@qq.com>
Date: Fri, 20 Dec 2024 13:36:00 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E7=89=A9=E4=B8=9A=20=E5=BC=80=E5=A7=8B?=
=?UTF-8?q?=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B4=20=E8=AE=A1=E7=AE=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../models/property_lease_contract.py | 25 +++++++++++++++++--
.../views/property_lease_contract.xml | 8 +++---
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py
index f9a6c5a5e..5e9a4d58e 100644
--- a/yuthon_property_approval/models/property_lease_contract.py
+++ b/yuthon_property_approval/models/property_lease_contract.py
@@ -42,8 +42,11 @@ class PropertyLeaseContract(models.Model):
tax_number = fields.Char(string="税号")
industry = fields.Char(string="行业")
address_for_delivery = fields.Char(string="送达地址")
- lease_term = fields.Integer(string="租期")
- lease_term_uom = fields.Selection([('year', '年'), ('month', '月')], default="year", 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='付款方式')
@@ -95,6 +98,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 = []
diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml
index 25710ce44..22af8395b 100644
--- a/yuthon_property_approval/views/property_lease_contract.xml
+++ b/yuthon_property_approval/views/property_lease_contract.xml
@@ -53,10 +53,12 @@
-
+
-
-
+
+
+
+