diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py
index f4b6489b3..3463ad4f0 100644
--- a/yuthon_property_approval/models/property_lease_contract.py
+++ b/yuthon_property_approval/models/property_lease_contract.py
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
+import pandas as pd
+from dateutil.relativedelta import relativedelta
+from datetime import datetime, timedelta
from odoo import models, fields, api, exceptions, _
+from odoo.exceptions import UserError, ValidationError
class PropertyLeaseContract(models.Model):
@@ -26,10 +29,15 @@ class PropertyLeaseContract(models.Model):
industry = fields.Char(string="行业")
address_for_delivery = fields.Char(string="送达地址")
lease_term = fields.Char(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='每月递增')
+ increment_percentage = fields.Float(string="递增百分比")
+ increment_price = fields.Float(string="递增单价")
+ increment_amount = fields.Float(string="递增金额")
rent_free_period = fields.Char(string="免租期")
breach_time = fields.Date(string="违约计算时点")
percentage_liquidated_damages = fields.Char(string="违约金比例")
@@ -45,6 +53,7 @@ class PropertyLeaseContract(models.Model):
not_tax_amount = fields.Float(string="不含税价")
tax = fields.Float(string="税金")
miscellaneous = fields.Char(string="其他约定")
+ total_area = fields.Float(string="总面积")
lease_ids = fields.One2many('property.lease.contract.line', 'lease_id',string="租赁信息明细行")
breakdown_ids = fields.One2many('property.rent.breakdown.line', 'breakdown_id', string="物业租金明细行")
@@ -64,13 +73,79 @@ class PropertyLeaseContract(models.Model):
contract_time = fields.Date(string="合同签订日期")
handover_time = fields.Date(string="交接日期")
+ @staticmethod
+ def divide_time_range_fixed(start_time, end_time, months):
+ time_ranges = []
+ while start_time < end_time:
+ end_of_range = start_time + relativedelta(months=months)
+ if end_of_range > end_time:
+ end_of_range = end_time
+ time_range = [start_time, end_of_range]
+ time_ranges.append(time_range)
+ start_time = end_of_range
+ return time_ranges
+
+ @staticmethod
+ def divide_time_range_floating(start_time, end_time, months):
+ time_ranges = []
+ while start_time < end_time:
+ start_time = start_time.replace(day=1)
+ end_of_range = start_time + relativedelta(months=months)
+ time_range = [start_time, end_of_range - relativedelta(days=1)]
+ time_ranges.append(time_range)
+ start_time = end_of_range
+ return time_ranges
+
def action_generate_details(self):
"""
生产租金明细
:return:
"""
- pass
-
+ # todo 还没有计算递增递减
+ # todo 还没有计算首月优惠
+ # todo 还没有计算开始和结束不足月份和季度的计算比例
+ for record in self:
+ self.sudo().env["property.rent.breakdown.line"].search([("breakdown_id", "=", record.id)]).unlink()
+ # 按照月度计算明细
+ if record.cycle_dict == "monthly":
+ months = 1
+ elif record.cycle_dict == "quarter":
+ months = 3
+ elif record.cycle_dict == "half":
+ months = 6
+ elif record.cycle_dict == "year":
+ months = 12
+ else:
+ raise UserError(_("请填写付款方式!"))
+ """
+ percentage','百分比'),('increment_price','递增单价'),('increment_amount','递增金额')
+ """
+ # unit_price = fields.Float(string="单价")
+ # monthly_amount = fields.Float(string="月租金")
+ # start_data = fields.Date(string="开始日期")
+ # end_data = fields.Date(string="结束日期")
+ # month_number = fields.Integer(string="期间月数")
+ # period_rent = fields.Float(string="期间租金")"""
+ start_date = record.term_start_time
+ end_date = record.term_end_time
+ if record.cycle_mode == "fixed":
+ # 按照月份、季度、年份进行分组
+ divided_time_segments = self.divide_time_range_fixed(start_date, end_date, months)
+ elif record.cycle_mode == "floating":
+ # 按照月份、季度、年份进行分组
+ divided_time_segments = self.divide_time_range_floating(start_date, end_date, months)
+ else:
+ raise UserError(_("请填写周期方式!"))
+ for segment in divided_time_segments:
+ self.sudo().env["property.rent.breakdown.line"].create({
+ "unit_price": record.unit_price,
+ "monthly_amount": record.total_area * record.unit_price,
+ "breakdown_id": record.id,
+ "start_data": segment[0],
+ "end_data": segment[1],
+ "month_number": months,
+ "period_rent": record.total_area * record.unit_price * months,
+ })
class PropertyLeaseContractLine(models.Model):
_name = 'property.lease.contract.line'
diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml
index 4c285354a..25ecda5b2 100644
--- a/yuthon_property_approval/views/property_lease_contract.xml
+++ b/yuthon_property_approval/views/property_lease_contract.xml
@@ -52,10 +52,20 @@
-
+
+
+
+
+
+
+
+
+
+
+