101 lines
3.8 KiB
Python
101 lines
3.8 KiB
Python
import datetime
|
|
import calendar
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class DepositPreReceivedReport(models.Model):
|
|
_inherit = 'property.accounts.receivable'
|
|
|
|
@api.model
|
|
def get_deposit_pre_received_report(self, params):
|
|
"""
|
|
押金前期实收报表:
|
|
- 数据源:property.accounts.receivable
|
|
- 管理费用类型为"押金"
|
|
- 押金状态为"已收"
|
|
- 非作废记录
|
|
- 支付日期(payout_date)在查询月之前(不含查询月)
|
|
- 金额:original_amount - discount_amount
|
|
"""
|
|
date_start = params.get("date_start")
|
|
query_date = datetime.datetime.fromisoformat(date_start).date() if date_start else datetime.date.today()
|
|
month_first = query_date.replace(day=1)
|
|
|
|
domain = [
|
|
('management_type_id.name', '=', '押金'),
|
|
('deposit_state', '=', 'paid'),
|
|
('is_invalid', '=', False),
|
|
('payout_date', '!=', False),
|
|
('payout_date', '<', month_first),
|
|
]
|
|
|
|
keyword = params.get("keyword")
|
|
if keyword:
|
|
domain += ['|', '|',
|
|
('contract_id.contract_code', 'ilike', keyword),
|
|
('property_name', 'ilike', keyword),
|
|
('lessee_id.name', 'ilike', keyword),
|
|
]
|
|
|
|
condition = params.get('condition')
|
|
partner_id = params.get('partner_id')
|
|
company_id = params.get('company_id')
|
|
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))
|
|
|
|
lines = self.sudo().search(domain, order="contract_id asc")
|
|
|
|
rows = []
|
|
total_amount = 0.0
|
|
for idx, rec in enumerate(lines, start=1):
|
|
amount = round((rec.original_amount or 0.0) - (rec.discount_amount or 0.0), 2)
|
|
total_amount += amount
|
|
|
|
contract = rec.contract_id
|
|
# 物业穿透
|
|
property_val = ''
|
|
if contract and contract.lease_ids and contract.lease_ids[0].address_id:
|
|
prop = contract.lease_ids[0].address_id
|
|
property_val = {
|
|
'model': 'yuthon.property',
|
|
'id': prop.id,
|
|
'display_name': rec.property_name or prop.name,
|
|
}
|
|
elif rec:
|
|
property_val = rec.property_name or ''
|
|
|
|
rows.append({
|
|
"序号": idx,
|
|
"合同编号": {
|
|
'model': 'property.lease.contract',
|
|
'id': contract.id,
|
|
'display_name': contract.contract_code,
|
|
} if contract else "",
|
|
"物业名称": property_val,
|
|
"承租方名称": {
|
|
'model': 'property.tenant.information',
|
|
'id': rec.lessee_id.id,
|
|
'display_name': rec.lessee_id.name,
|
|
} if rec.lessee_id else "",
|
|
"收款日期": rec.payout_date.strftime("%Y-%m-%d") if rec.payout_date else "",
|
|
"金额": amount,
|
|
"应收金额": round((rec.original_amount or 0.0) - (rec.discount_amount or 0.0), 2),
|
|
"所属公司": rec.company_id.name if rec.company_id else "",
|
|
"管理员": {
|
|
'model': 'res.users',
|
|
'id': rec.admin_id.id,
|
|
'display_name': rec.admin_id.name,
|
|
} if rec.admin_id else "",
|
|
})
|
|
|
|
stats = [
|
|
{'name': '记录总数', 'amount': len(rows)},
|
|
{'name': '合计金额', 'amount': round(total_amount, 2)},
|
|
]
|
|
return {"rows": rows, "stats": stats}
|