This commit is contained in:
李鹏宇
2026-03-16 19:43:30 +08:00
parent e92b6e4448
commit 65e5f36117
2 changed files with 69 additions and 70 deletions
+35 -35
View File
@@ -4,19 +4,20 @@ from odoo import api, models
class PreAdvanceReport(models.Model):
_inherit = 'property.accounts.receivable'
_inherit = 'receivable.modify.line'
@api.model
def get_pre_advance_report(self, params):
"""
前期预收报表:
- 应收日期(due_date)在本月最后一天之后(未来应收)
- 已提前收款:delivered1 > 0
- 非作废:is_invalid = False
- 按合同分组,金额 = sum(delivered1)(已收金额)
前期预收报表(数据源:receivable.modify.line):
- 应收开始日期(receivable_id.due_date)在查询月最后一天之后(未来应收)
- 应收账单未收金额(receivable_id.submitted)= 0(已全额收款)
- original_amount > 0(有交易金额)
- 应收账单非作废:receivable_id.is_invalid = False
- 排除押金和违约金类型
- 金额取 original_amount(交易金额)
"""
today = datetime.date.today()
# 本月最后一天
if today.month == 12:
next_month_first = today.replace(year=today.year + 1, month=1, day=1)
else:
@@ -28,41 +29,44 @@ class PreAdvanceReport(models.Model):
cutoff_date = datetime.datetime.fromisoformat(date_end).date() if date_end else this_month_last
domain = [
('due_date', '>', cutoff_date),
('submitted', '=', 0),
('receivable_id.due_date', '>', cutoff_date),
('receivable_id.submitted', '=', 0),
('original_amount', '>', 0),
('is_invalid', '=', False),
('receivable_id.is_invalid', '=', False),
('receivable_id.management_type_id.name', 'not in', ['押金', '违约金']),
]
keyword = params.get("keyword")
if keyword:
domain += [
'|', '|',
('contract_id.contract_code', 'ilike', keyword),
('property_name', 'ilike', keyword),
('lessee_id.name', 'ilike', keyword),
('receivable_id.contract_id.contract_code', 'ilike', keyword),
('receivable_id.property_name', 'ilike', keyword),
('receivable_id.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))
receivables = self.search(domain, order="contract_id asc, due_date asc")
lines = self.search(domain, order="receivable_id asc, receivable_id.due_date asc")
rows = []
total_amount = 0.0
for idx, rec in enumerate(receivables, start=1):
contract = rec.contract_id
amount = round(rec.original_amount or 0.0, 2)
for idx, line in enumerate(lines, start=1):
rec = line.receivable_id
contract = rec.contract_id if rec else None
amount = round(line.original_amount or 0.0, 2)
total_amount += amount
# 物业穿透
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,
"合同编号": {
@@ -70,22 +74,18 @@ class PreAdvanceReport(models.Model):
'id': contract.id,
'display_name': contract.contract_code,
} if contract else "",
"物业名称": {
'model': 'yuthon.property',
'id': rec.contract_id.lease_ids[0].address_id.id,
'display_name': rec.property_name,
} if rec.contract_id and rec.contract_id.lease_ids and rec.contract_id.lease_ids[0].address_id else rec.property_name or "",
"物业名称": property_val,
"承租方名称": {
'model': 'property.tenant.information',
'id': rec.lessee_id.id,
'display_name': rec.lessee_id.name,
} if rec.lessee_id else "",
} if rec and rec.lessee_id else "",
"金额": amount,
"管理员": {
'model': 'res.users',
'id': rec.admin_id.id,
'display_name': rec.admin_id.name,
} if rec.admin_id else "",
} if rec and rec.admin_id else "",
})
stats = [
+34 -35
View File
@@ -4,60 +4,63 @@ from odoo import api, models
class PreArrearsReport(models.Model):
_inherit = 'property.accounts.receivable'
_inherit = 'receivable.modify.line'
@api.model
def get_pre_arrears_report(self, params):
"""
前期欠收报表:
- 应收日期(due_date)在本月第一天之前
- 未收金额(submitted)> 0,即 original_amount > delivered1
- 非作废(is_invalid == False)
- 按合同分组,金额 = sum(submitted)
前期欠收报表(数据源:receivable.modify.line):
- 应收开始日期(receivable_id.due_date)在查询月第一天之前
- 应收账单未收金额(receivable_id.submitted)> 0
- 应收账单非作废(receivable_id.is_invalid = False)
- 排除押金和违约金类型
- 金额取 original_amount(交易金额)
"""
today = datetime.date.today()
this_month_first = today.replace(day=1)
date_start = params.get("date_start")
date_end = params.get("date_end")
# 前期欠收:due_date 在查询起始日期之前(若无传值则取本月第一天)
cutoff_date = datetime.datetime.fromisoformat(date_start).date() if date_start else this_month_first
domain = [
('due_date', '<', cutoff_date),
('submitted', '>', 0),
('is_invalid', '=', False),
('receivable_id.due_date', '<', cutoff_date),
('receivable_id.submitted', '>', 0),
('receivable_id.is_invalid', '=', False),
('receivable_id.management_type_id.name', 'not in', ['押金', '违约金']),
]
keyword = params.get("keyword")
if keyword:
domain += [
'|', '|',
('contract_id.contract_code', 'ilike', keyword),
('property_name', 'ilike', keyword),
('lessee_id.name', 'ilike', keyword),
('receivable_id.contract_id.contract_code', 'ilike', keyword),
('receivable_id.property_name', 'ilike', keyword),
('receivable_id.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))
receivables = self.search(domain, order="contract_id asc, due_date asc")
lines = self.search(domain, order="receivable_id asc, receivable_id.due_date asc")
rows = []
total_amount = 0.0
for idx, rec in enumerate(receivables, start=1):
contract = rec.contract_id
amount = round(rec.submitted or 0.0, 2)
for idx, line in enumerate(lines, start=1):
rec = line.receivable_id
contract = rec.contract_id if rec else None
amount = round(line.original_amount or 0.0, 2)
total_amount += amount
# 物业穿透
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,
"合同编号": {
@@ -65,23 +68,19 @@ class PreArrearsReport(models.Model):
'id': contract.id,
'display_name': contract.contract_code,
} if contract else "",
"物业名称": {
'model': 'yuthon.property',
'id': rec.contract_id.lease_ids[0].address_id.id,
'display_name': rec.property_name,
} if rec.contract_id and rec.contract_id.lease_ids and rec.contract_id.lease_ids[0].address_id else rec.property_name or "",
"物业名称": property_val,
"承租方名称": {
'model': 'property.tenant.information',
'id': rec.lessee_id.id,
'display_name': rec.lessee_id.name,
} if rec.lessee_id else "",
} if rec and rec.lessee_id else "",
"金额": amount,
"所属公司": contract.lessor_id.name if contract and contract.lessor_id else "",
"管理员": {
'model': 'res.users',
'id': rec.admin_id.id,
'display_name': rec.admin_id.name,
} if rec.admin_id else "",
} if rec and rec.admin_id else "",
})
stats = [