diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index 140cad350..18eaf3edf 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -49,6 +49,10 @@ class PropertyLeaseContract(models.Model): cycle_mode = fields.Selection([('fixed','合同月'), ('floating','自然月')],string='周期方式') expected_reminders = fields.Char(string="逾期提醒") increment_method = fields.Selection([('percentage','百分比'),('increment_price','递增单价'),('increment_amount','递增金额')], 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="递增金额") @@ -114,7 +118,7 @@ class PropertyLeaseContract(models.Model): def action_generate_rental_charges(self): """ - 生成租金明细 + 生成租金费用明细 :return: """ for record in self: @@ -123,64 +127,62 @@ class PropertyLeaseContract(models.Model): if not record.term_end_time: raise UserError(_("请填写租期结束时间!")) self.sudo().env["property.rent.list"].search([("contract_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(_("请填写付款方式!")) - # 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 - # 先按照年分组 - divided_year_segments = self.divide_time_range_fixed(start_date, end_date, 12) - index = 0 # 第几年 - period_rent = 0 # 月租金 - unit_price = 0 # 单价 - for segment_year in divided_year_segments: - index += 1 - """ - increment_percentage = fields.Float(string="递增百分比") - increment_price = fields.Float(string="递增单价") - increment_amount = fields.Float(string="递增金额") - """ - if index > 1: + 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 # 月租金 + unit_price = record.unit_price # 单价 + # 先计算免租期 + 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 not increments_every_few_years: + delta = relativedelta(end_date, increments_start) + months = delta.years * 12 + delta.months + all_period_rent += period_rent * months + else: + # 开始递增 + divided_increments_segments = self.divide_time_range_fixed(increments_start, end_date, increments_every_few_years * 12) + index = 0 # 第几递增周期年 + for increments_year in divided_increments_segments: + index += 1 + """ + increment_percentage = fields.Float(string="递增百分比") + increment_price = fields.Float(string="递增单价") + increment_amount = fields.Float(string="递增金额") + """ + delta = relativedelta(increments_year[1], increments_year[0]) + months = delta.years * 12 + delta.months 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 - else: - period_rent = record.total_area * record.unit_price - unit_price = record.unit_price - divided_time_segments = self.divide_time_range_fixed(segment_year[0], segment_year[1], months) - # if record.cycle_mode == "fixed": - # # 按照月份、季度、年份进行分组 - # divided_time_segments = self.divide_time_range_fixed(segment_year[0], segment_year[1], months) - # elif record.cycle_mode == "floating": - # # 按照月份、季度、年份进行分组 - # divided_time_segments = self.divide_time_range_floating(segment_year[0], segment_year[1], months) - # else: - # raise UserError(_("请填写周期方式!")) - for segment in divided_time_segments: - self.sudo().env["property.rent.list"].create({ - "contract_id": record.id, - "contract_code": record.code, - "due_date": segment[0], - "original_amount": period_rent * months, - }) + unit_price = period_rent / record.total_area + all_period_rent += period_rent * months + + self.sudo().env["property.rent.list"].create({ + "contract_id": record.id, + "contract_code": record.code, + "due_date": start_date, + "original_amount": all_period_rent, + }) def action_generate_administrative_expenses(self): """ @@ -193,72 +195,18 @@ class PropertyLeaseContract(models.Model): if not record.term_end_time: raise UserError(_("请填写租期结束时间!")) self.sudo().env["property.management.list"].search([("contract_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(_("请填写付款方式!")) - # 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 - # 先按照年分组 - divided_year_segments = self.divide_time_range_fixed(start_date, end_date, 12) - index = 0 # 第几年 - for segment_year in divided_year_segments: - index += 1 - """ - increment_percentage = fields.Float(string="递增百分比") - increment_price = fields.Float(string="递增单价") - increment_amount = fields.Float(string="递增金额") - """ - divided_time_segments = self.divide_time_range_fixed(segment_year[0], segment_year[1], months) - # if record.cycle_mode == "fixed": - # # 按照月份、季度、年份进行分组 - # divided_time_segments = self.divide_time_range_fixed(segment_year[0], segment_year[1], months) - # elif record.cycle_mode == "floating": - # # 按照月份、季度、年份进行分组 - # divided_time_segments = self.divide_time_range_floating(segment_year[0], segment_year[1], months) - # else: - # raise UserError(_("请填写周期方式!")) - for segment in divided_time_segments: - """ - contract_code = fields.Char(string='合同编号', required=True) - property_id = fields.Many2one('yuthon.property', string='物业') - lessee_id = fields.Many2one('yuthon.property.lessee', string='承租方') - due_date = fields.Date(string='应收日期') - year = fields.Char(string='所属年') - month = fields.Char(string='所属月') - management_fee_standard = fields.Float(string='管理费标准') - original_amount = fields.Float(string='原金额') - reduction_amount = fields.Float(string='减免金额') - remarks = fields.Text(string='备注') - is_cancel = fields.Boolean(string='是否作废') - is_red = fields.Boolean(string='是否红冲') - red_date = fields.Date(string='红冲日期') - charge_status = fields.Selection([('not_paid', '未收'), ('paid', '已收')], string='收费状态') - is_invoice = fields.Boolean(string='是否开票') - is_suspend = fields.Boolean(string='是否挂起') - create_time = fields.Datetime(string='创建时间') - last_update_time = fields.Datetime(string='最后修改时间') - """ - self.sudo().env["property.management.list"].create({ - "contract_id": record.id, - "contract_code": record.code, - "due_date": segment[0], - "original_amount": record.total_area * record.management_fee * months, - }) + delta = relativedelta(end_date, start_date) + months = delta.years * 12 + delta.months + self.sudo().env["property.management.list"].create({ + "contract_id": record.id, + "contract_code": record.code, + "due_date": start_date, + "original_amount": record.total_area * record.management_fee * months, + }) + def action_generate_details(self): """ @@ -274,68 +222,82 @@ class PropertyLeaseContract(models.Model): if not record.term_end_time: raise UserError(_("请填写租期结束时间!")) 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(_("请填写付款方式!")) - # 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 - # 先按照年分组 - divided_year_segments = self.divide_time_range_fixed(start_date, end_date, 12) - index = 0 # 第几年 - period_rent = 0 # 月租金 - unit_price = 0 # 单价 - for segment_year in divided_year_segments: - index += 1 - """ - increment_percentage = fields.Float(string="递增百分比") - increment_price = fields.Float(string="递增单价") - increment_amount = fields.Float(string="递增金额") - """ - if index > 1: - 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 - if record.increment_amount: - period_rent = period_rent + record.increment_amount - else: - period_rent = record.total_area * record.unit_price - unit_price = record.unit_price - divided_time_segments = self.divide_time_range_fixed(segment_year[0], segment_year[1], months) - # if record.cycle_mode == "fixed": - # # 按照月份、季度、年份进行分组 - # divided_time_segments = self.divide_time_range_fixed(segment_year[0], segment_year[1], months) - # elif record.cycle_mode == "floating": - # # 按照月份、季度、年份进行分组 - # divided_time_segments = self.divide_time_range_floating(segment_year[0], segment_year[1], months) - # else: - # raise UserError(_("请填写周期方式!")) - for segment in divided_time_segments: + 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 # 月租金 + unit_price = record.unit_price # 单价 + + # 先计算免租期 + first_index = 0 # 第几递增周期年 + increments_start = start_date # 递增开始 + # 第几年不递增 + if not increments_every_few_years: + delta = relativedelta(end_date, increments_start) + months = delta.years * 12 + delta.months + self.sudo().env["property.rent.breakdown.line"].create({ + "unit_price": unit_price, + "monthly_amount": period_rent, + "breakdown_id": record.id, + "start_data": increments_start, + "end_data": end_date, + "month_number": months, + "period_rent": period_rent * months, + }) + else: + 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 self.sudo().env["property.rent.breakdown.line"].create({ "unit_price": unit_price, "monthly_amount": period_rent, "breakdown_id": record.id, - "start_data": segment[0], - "end_data": segment[1], + "start_data": start_date, + "end_data": increments_start, "month_number": months, "period_rent": period_rent * months, }) + # 开始递增 + divided_increments_segments = self.divide_time_range_fixed(increments_start, end_date, increments_every_few_years*12) + index = 0 # 第几递增周期年 + for increments_year in divided_increments_segments: + index += 1 + """ + increment_percentage = fields.Float(string="递增百分比") + 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 + self.sudo().env["property.rent.breakdown.line"].create({ + "unit_price": unit_price, + "monthly_amount": period_rent, + "breakdown_id": record.id, + "start_data": increments_year[0], + "end_data": increments_year[1], + "month_number": months, + "period_rent": period_rent * months, + }) + class PropertyLeaseContractLine(models.Model): _name = 'property.lease.contract.line' _description = '物业列表明细行' diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml index 5e36446df..a1dfa9031 100644 --- a/yuthon_property_approval/views/property_lease_contract.xml +++ b/yuthon_property_approval/views/property_lease_contract.xml @@ -17,8 +17,8 @@
-
@@ -67,6 +67,10 @@ + + + + @@ -109,7 +113,7 @@ -