添加功能

This commit is contained in:
zhou
2025-01-11 19:00:33 +08:00
parent 8b351d1357
commit 0b97060ca5
2 changed files with 66 additions and 27 deletions
@@ -7,7 +7,6 @@ class PropertyRentalWizard(models.Model):
_name = 'property.rental.wizard'
_description = '物业应收明细向导'
lease_contract_id = fields.Many2one('property.lease.contract', string="合同")
select_month = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'),
('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'),
('9', '九月'), ('10', '十月'), ('11', '十一月'),
@@ -23,29 +22,70 @@ class PropertyRentalWizard(models.Model):
'生成租金明细‘
:return:
"""
for record in self.lease_contract_id:
if not record.term_start_time:
raise UserError(_("请填写租期开始时间!"))
if not record.term_end_time:
raise UserError(_("请填写租期结束时间!"))
rent_id = self.sudo().env["property.rent.list"].search([("contract_id", "=", record.id)])
start_date = record.term_start_time
rent_monthly = record.get_breakdown_rent(self.select_month, self.select_year)
if not rent_id:
self.sudo().env["property.rent.list"].create({
"contract_id": record.id,
"contract_code": record.code,
"due_date": start_date,
"original_amount": rent_monthly,
"year": self.select_year,
'month': self.select_month,
})
rent_monthly = 0
monthly_records = self.env['property.lease.contract'].search([('cycle_dict', '=', 'monthly')])
year = int(self.select_year)
month = int(self.select_month)
date_field = datetime(year, month, 1).date()
for record in monthly_records:
days = record.date_payment_month
if not record.rent_free_period_month:
for rent_id in record.breakdown_ids:
start_date_year_month = rent_id.start_data.strftime('%Y-%m')
end_date_year_month = rent_id.end_data.strftime('%Y-%m')
date_field_year_month = date_field.strftime('%Y-%m')
if start_date_year_month <= date_field_year_month < end_date_year_month:
rent_monthly = rent_id.monthly_amount
elif start_date_year_month <= date_field_year_month <= end_date_year_month:
end_days = rent_id.end_data.day
if end_days < days:
rent_monthly = rent_id.monthly_amount
try:
rent_monthly = rent_id[+1].monthly_amount
except IndexError:
continue
else:
pass
else:
rent_id.write({
"contract_id": record.id,
"contract_code": record.code,
"due_date": start_date,
"original_amount": rent_monthly,
"year": self.select_year,
'month': self.select_month,
})
period_month = record.rent_free_period_month
for rent_id in record.breakdown_ids:
start_date_year_month = (rent_id.start_data + relativedelta(months=period_month)).strftime('%Y-%m')
end_date_year_month = rent_id.end_data.strftime('%Y-%m')
date_field_year_month = date_field.strftime('%Y-%m')
if start_date_year_month <= date_field_year_month < end_date_year_month:
rent_monthly = rent_id.monthly_amount
elif start_date_year_month <= date_field_year_month <= end_date_year_month:
end_days = rent_id.end_data.day
if end_days < days:
rent_monthly = rent_id.monthly_amount
try:
rent_monthly = rent_id[+1].monthly_amount
except IndexError:
continue
else:
pass
if rent_monthly:
if not record.term_start_time:
raise UserError(_("请填写租期开始时间!"))
if not record.term_end_time:
raise UserError(_("请填写租期结束时间!"))
rent_id = self.sudo().env["property.rent.list"].search([("contract_id", "=", record.id)])
start_date = record.term_start_time
if not rent_id:
self.sudo().env["property.rent.list"].create({
"contract_id": record.id,
"contract_code": record.code,
"due_date": start_date,
"original_amount": rent_monthly,
"year": self.select_year,
'month': self.select_month,
})
else:
rent_id.write({
"contract_id": record.id,
"contract_code": record.code,
"due_date": start_date,
"original_amount": rent_monthly,
"year": self.select_year,
'month': self.select_month,
})
@@ -21,7 +21,6 @@
</group>
</group>
<group>
<field name="lease_contract_id" invisible="1"/>
<field name="select_month"/>
<field name="select_year"/>
</group>