135 lines
5.7 KiB
Python
135 lines
5.7 KiB
Python
import datetime
|
|
|
|
from odoo import fields, models, api
|
|
|
|
|
|
class YuthonProperty(models.Model):
|
|
_inherit = 'yuthon.property'
|
|
|
|
@api.model
|
|
def get_complete_ledger_report(self, params):
|
|
domain = [('purpose_id.name', '=', '可租')]
|
|
# if params.get("date_start"):
|
|
# date_start = datetime.datetime.fromisoformat(params.get("date_start")).date()
|
|
# domain.append(("due_date", ">=", date_start))
|
|
# if params.get("date_end"):
|
|
# date_end = datetime.datetime.fromisoformat(params.get("date_end")).date()
|
|
# domain.append(("due_date", "<=", date_end))
|
|
|
|
condition = params.get('condition', False)
|
|
partner_id = params.get('partner_id', False)
|
|
company_id = params.get('company_id', False)
|
|
management_type_id = params.get('management_type_id', False)
|
|
|
|
if condition:
|
|
domain.append(('tenure_type', '=', condition))
|
|
|
|
if partner_id:
|
|
domain.append(('precinct_id', '=', partner_id))
|
|
if company_id:
|
|
domain.append(('company_id', '=', company_id))
|
|
|
|
if management_type_id:
|
|
domain.append(('management_type_id', '=', management_type_id))
|
|
|
|
properties = self.search(domain, limit=100)
|
|
result = []
|
|
|
|
if partner_id:
|
|
admin_properties = self.env['yuthon.property'].search([
|
|
('precinct_id', '=', partner_id),
|
|
])
|
|
# 统计管理员下总面积
|
|
total_rentable_area = sum(
|
|
prop.rent_area for prop in admin_properties
|
|
if prop.property_state == 'on_rent' and prop.rent_area
|
|
)
|
|
# 统计管理员下所有空置面积
|
|
total_vacant_area = sum(
|
|
prop.rent_area for prop in admin_properties
|
|
if prop.property_state == 'vacant' and prop.rent_area
|
|
)
|
|
if total_rentable_area > 0:
|
|
rental_rate = round(((total_rentable_area - total_vacant_area) / total_rentable_area) * 100, 2)
|
|
|
|
admin_contracts = self.env['property.lease.contract'].search([
|
|
('precinct_id', '=', partner_id),
|
|
('contact_state', '=', 'ing')
|
|
])
|
|
|
|
if admin_contracts:
|
|
receivable_domain = [
|
|
('contract_id', 'in', admin_contracts.ids),
|
|
]
|
|
if params.get("date_end"):
|
|
date_end = datetime.datetime.fromisoformat(params.get("date_end")).date()
|
|
receivable_domain.append(('due_date', '<=', date_end))
|
|
receivable_records = self.env['property.accounts.receivable'].search(receivable_domain)
|
|
if receivable_records:
|
|
total_delivered = sum(rec.delivered1 for rec in receivable_records) # 已交金额
|
|
total_amount = sum(rec.original_amount for rec in receivable_records) # 当期金额
|
|
if total_amount > 0:
|
|
collection_rate = round((total_delivered / total_amount) * 100, 2)
|
|
else:
|
|
collection_rate = 0.0
|
|
else:
|
|
collection_rate = 0.0
|
|
else:
|
|
collection_rate = 0.0
|
|
else:
|
|
rental_rate = 0.0
|
|
collection_rate = 0.0
|
|
|
|
for p in properties:
|
|
if params.get("date_end"):
|
|
date_end = datetime.datetime.fromisoformat(params.get("date_end")).date()
|
|
valid_info = p.manage_information_ids.filtered(
|
|
lambda info: info.start_time <= date_end and
|
|
(not info.end_date or info.end_date >= date_end)
|
|
)
|
|
else:
|
|
valid_info = p.manage_information_ids[-1]
|
|
management_area = valid_info.management_area if valid_info else 0
|
|
rent_area = valid_info.rent_area if valid_info else 0
|
|
lease_id = self.env['property.lease.contract.line'].search([
|
|
('address_id', '=', p.id),
|
|
('lease_id.contact_state', '=', 'ing')
|
|
], limit=1)
|
|
if lease_id:
|
|
contract_id = lease_id.lease_id
|
|
else:
|
|
contract_id = False
|
|
|
|
if p.property_state == 'on_rent':
|
|
leased_area = rent_area
|
|
else:
|
|
leased_area = 0.0
|
|
|
|
result.append({
|
|
"物业名称": p.name or "",
|
|
"用途": p.asset_type_id.name,
|
|
"产权证号": p.title_deed,
|
|
"产权面积": p.equity_area or 0.0,
|
|
"管理面积": management_area or 0.0,
|
|
"可租面积": rent_area or 0.0,
|
|
"已租面积": leased_area or 0.0,
|
|
"出租率": rental_rate ,
|
|
"收费率": collection_rate,
|
|
"所属公司": contract_id.lessor_id.referred if contract_id else "",
|
|
"租赁状态": "在租" if p.property_state == 'on_rent' else "空置" if p.property_state == 'vacant' else "",
|
|
"合同编号": {
|
|
'model': 'property.lease.contract',
|
|
'id': contract_id.id,
|
|
'display_name': contract_id.contract_code,
|
|
} if contract_id else "",
|
|
"承租方": {
|
|
'model': 'property.tenant.information',
|
|
'id': contract_id.lessee_id.id,
|
|
'display_name': contract_id.lessee_id.name,
|
|
} if contract_id and contract_id.lessee_id else "",
|
|
"单价": contract_id.unit_price if contract_id else 0,
|
|
"租金": contract_id.rent if contract_id else 0,
|
|
"管理员": p.admin_id.name,
|
|
})
|
|
|
|
return result |