From 8de7790856fba10a7a90c84ce50030c07fd6fed4 Mon Sep 17 00:00:00 2001 From: ljmwkx <1340053001@qq.com> Date: Mon, 6 Jan 2025 20:57:39 +0800 Subject: [PATCH 1/3] 1 --- .../models/property_lease_contract.py | 93 ++++++++++--------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index 2e8b01c98..df4ea0290 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -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, From b68bb22f1aee565df78b920b545a18d63d1c89ec Mon Sep 17 00:00:00 2001 From: ljmwkx <1340053001@qq.com> Date: Mon, 6 Jan 2025 21:01:40 +0800 Subject: [PATCH 2/3] 1 --- yuthon_property_approval/views/property_lease_contract.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml index 124cf9d2e..1de6e5272 100644 --- a/yuthon_property_approval/views/property_lease_contract.xml +++ b/yuthon_property_approval/views/property_lease_contract.xml @@ -79,7 +79,7 @@ - + From 44388afd8bd16e8056df90aef1a89843606f1cbb Mon Sep 17 00:00:00 2001 From: ljmwkx <1340053001@qq.com> Date: Mon, 6 Jan 2025 21:03:22 +0800 Subject: [PATCH 3/3] 1 --- yuthon_property_approval/views/property_lease_contract.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml index 1de6e5272..0fda574a9 100644 --- a/yuthon_property_approval/views/property_lease_contract.xml +++ b/yuthon_property_approval/views/property_lease_contract.xml @@ -342,7 +342,7 @@ - +