109 lines
4.0 KiB
Python
109 lines
4.0 KiB
Python
import datetime
|
|
import calendar
|
|
import logging
|
|
|
|
from odoo import api, models
|
|
from .report_utils import _id_list # 导入 ID 列表解析工具函数,支持多选参数
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class PropertyBillsList(models.Model):
|
|
_inherit = 'property.bills.list'
|
|
|
|
@api.model
|
|
def get_assessment_fee_monthly_report(self, params):
|
|
"""评估费本月支出报表。
|
|
|
|
数据源:property.bills.list
|
|
过滤条件:
|
|
- management_type_id.name = '评估费'
|
|
- actual_date(实付日期)在查询月本月范围内(月初~月末)
|
|
字段:应付日期、实付日期、应付、实付、标题
|
|
"""
|
|
# ========== 一、参数解析 ==========
|
|
date_start = params.get("date_start")
|
|
keyword = params.get("keyword")
|
|
|
|
# ========== 二、查询日期解析 ==========
|
|
if date_start:
|
|
try:
|
|
query_date = datetime.datetime.fromisoformat(date_start.split(' ')[0]).date()
|
|
except Exception:
|
|
query_date = datetime.date.today()
|
|
else:
|
|
query_date = datetime.date.today()
|
|
|
|
# 计算查询月月初和月末
|
|
month_first = query_date.replace(day=1)
|
|
_, last_day = calendar.monthrange(query_date.year, query_date.month)
|
|
month_last = query_date.replace(day=last_day)
|
|
|
|
# ========== 三、构建domain ==========
|
|
domain = [
|
|
('management_type_id.name', '=', '评估费'),
|
|
('actual_date', '>=', month_first),
|
|
('actual_date', '<=', month_last),
|
|
]
|
|
|
|
# 关键字过滤
|
|
if keyword:
|
|
domain += ['|', '|', '|',
|
|
('name', 'ilike', keyword),
|
|
('contract_id.contract_code', 'ilike', keyword),
|
|
('lessee_id.name', 'ilike', keyword),
|
|
('property_name', 'ilike', keyword),
|
|
]
|
|
|
|
# 公司/片区过滤
|
|
company_id = _id_list(params.get('company_id'))
|
|
partner_id = _id_list(params.get('partner_id')) # 解析片区 ID 为整数列表(多选支持)
|
|
if company_id:
|
|
domain.append(('lessor_id', 'in', company_id))
|
|
if partner_id:
|
|
domain += ['|',
|
|
('contract_id.precinct_id', 'in', partner_id), # 合同片区过滤(多选支持)
|
|
('receivables_id.precinct_id', 'in', partner_id), # 应收记录片区过滤(多选支持)
|
|
]
|
|
|
|
# 查询记录
|
|
records = self.sudo().search(domain)
|
|
|
|
# ========== 四、构建报表行 ==========
|
|
rows = []
|
|
total_amount = 0.0 # 应付合计
|
|
total_amount_actual = 0.0 # 实付合计
|
|
|
|
for idx, rec in enumerate(records, start=1):
|
|
due_date_str = rec.due_date.strftime("%Y-%m-%d") if rec.due_date else ""
|
|
actual_date_str = rec.actual_date.strftime("%Y-%m-%d") if rec.actual_date else ""
|
|
amount_val = round(rec.amount or 0.0, 2)
|
|
amount_actual_val = round(rec.amount_actual or 0.0, 2)
|
|
|
|
total_amount += amount_val
|
|
total_amount_actual += amount_actual_val
|
|
|
|
rows.append({
|
|
"序号": idx,
|
|
"应付日期": due_date_str,
|
|
"实付日期": actual_date_str,
|
|
"应付": amount_val,
|
|
"实付": amount_actual_val,
|
|
"标题": rec.name or "",
|
|
})
|
|
|
|
# ========== 五、构建统计汇总数据 ==========
|
|
stats = [
|
|
{'name': '记录总数', 'amount': len(rows)},
|
|
{'name': '应付合计', 'amount': round(total_amount, 2)},
|
|
{'name': '实付合计', 'amount': round(total_amount_actual, 2)},
|
|
]
|
|
|
|
_logger.info(
|
|
"[ASSESSMENT_FEE_MONTHLY] query_date=%s, month_range=[%s, %s], rows=%d, "
|
|
"total_amount=%.2f, total_amount_actual=%.2f",
|
|
query_date, month_first, month_last, len(rows), total_amount, total_amount_actual,
|
|
)
|
|
|
|
return {"rows": rows, "stats": stats}
|