物业合同管理 计算

This commit is contained in:
ljmwkx
2024-12-10 12:20:11 +08:00
parent 78606aa208
commit 7e116cd7ab
2 changed files with 89 additions and 4 deletions
@@ -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'
@@ -52,10 +52,20 @@
<field name="cycle_mode"/>
</group>
<group>
<field name="expected_reminders"/>
<field name="expected_reminders"/>
<field name="increment_method"/>
<field name="rent_free_period"/>
</group>
<group>
<field name="increment_percentage"/>
<field name="increment_price"/>
<field name="increment_amount"/>
</group>
<group>
<field name="term_start_time" />
<field name="term_end_time" />
<field name="total_area" />
</group>
<group>
<field name="breach_time"/>
<field name="percentage_liquidated_damages"/>