押金报表
This commit is contained in:
@@ -1,85 +1,84 @@
|
||||
import datetime
|
||||
import calendar
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class DepositCumArrearsReport(models.Model):
|
||||
_inherit = 'receivable.modify.line'
|
||||
_inherit = 'property.accounts.receivable'
|
||||
|
||||
@api.model
|
||||
def get_deposit_cum_arrears_report(self, params):
|
||||
"""
|
||||
押金累计欠收报表:
|
||||
- 数据源:receivable.modify.line
|
||||
- 应收类型为"押金"
|
||||
- due_date < 查询月月初(查询月之前,不含查询月)
|
||||
- not_collected > 0(到查询月还没收的,即未收金额)
|
||||
- is_invalid = False
|
||||
- 数据源:property.accounts.receivable
|
||||
- 管理费用类型为"押金"
|
||||
- 非作废记录
|
||||
- 应收日期(due_date)在查询月内(包含查询月)
|
||||
- 有欠收金额(submitted > 0)
|
||||
- 金额:submitted(未收金额)
|
||||
"""
|
||||
today = datetime.date.today()
|
||||
this_month_first = today.replace(day=1)
|
||||
|
||||
date_start = params.get("date_start")
|
||||
date_end = params.get("date_end")
|
||||
|
||||
# 查询月月初:用 date_start 所在月的第一天
|
||||
if date_start:
|
||||
query_date = datetime.datetime.fromisoformat(date_start).date()
|
||||
month_first = query_date.replace(day=1)
|
||||
else:
|
||||
month_first = this_month_first
|
||||
|
||||
deposit_type = self.env['yuthon.management.type'].search([('name', '=', '押金')], limit=1)
|
||||
query_date = datetime.datetime.fromisoformat(date_start).date() if date_start else datetime.date.today()
|
||||
month_first = query_date.replace(day=1)
|
||||
last_day = calendar.monthrange(query_date.year, query_date.month)[1]
|
||||
month_last = query_date.replace(day=last_day)
|
||||
|
||||
domain = [
|
||||
('receivable_id.due_date', '<', month_first), # 查询月之前,不含查询月
|
||||
('receivable_id.submitted', '>', 0), # 未收金额 > 0
|
||||
('receivable_id.is_invalid', '=', False),
|
||||
('management_type_id.name', '=', '押金'),
|
||||
('is_invalid', '=', False),
|
||||
('due_date', '>=', month_first),
|
||||
('due_date', '<=', month_last),
|
||||
('submitted', '>', 0),
|
||||
]
|
||||
if deposit_type:
|
||||
domain.append(('management_type_id', '=', deposit_type.id))
|
||||
|
||||
keyword = params.get("keyword")
|
||||
if keyword:
|
||||
domain += ['|', '|',
|
||||
('receivable_id.contract_id.contract_code', 'ilike', keyword),
|
||||
('contract_id.contract_code', 'ilike', keyword),
|
||||
('property_name', 'ilike', keyword),
|
||||
('receivable_id.lessee_id.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(('receivable_id.tenure_type', '=', condition))
|
||||
domain.append(('tenure_type', '=', condition))
|
||||
if partner_id:
|
||||
domain.append(('receivable_id.precinct_id', '=', partner_id))
|
||||
domain.append(('precinct_id', '=', partner_id))
|
||||
if company_id:
|
||||
domain.append(('receivable_id.company_id', '=', company_id))
|
||||
domain.append(('company_id', '=', company_id))
|
||||
|
||||
lines = self.search(domain, order="receivable_id asc")
|
||||
lines = self.sudo().search(domain, order="contract_id asc")
|
||||
|
||||
rows = []
|
||||
total_amount = 0.0
|
||||
idx = 1
|
||||
for line in lines:
|
||||
rec = line.receivable_id
|
||||
for idx, rec in enumerate(lines, start=1):
|
||||
amount = round(rec.submitted or 0.0, 2)
|
||||
if amount <= 0:
|
||||
continue
|
||||
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': rec.contract_id.id,
|
||||
'display_name': rec.contract_id.contract_code,
|
||||
} if rec.contract_id 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 "",
|
||||
'id': contract.id,
|
||||
'display_name': contract.contract_code,
|
||||
} if contract else "",
|
||||
"物业名称": property_val,
|
||||
"承租方名称": {
|
||||
'model': 'property.tenant.information',
|
||||
'id': rec.lessee_id.id,
|
||||
@@ -93,7 +92,6 @@ class DepositCumArrearsReport(models.Model):
|
||||
'display_name': rec.admin_id.name,
|
||||
} if rec.admin_id else "",
|
||||
})
|
||||
idx += 1
|
||||
|
||||
stats = [
|
||||
{'name': '记录总数', 'amount': len(rows)},
|
||||
|
||||
@@ -26,7 +26,7 @@ class DepositMonthReceivedReport(models.Model):
|
||||
|
||||
domain = [
|
||||
('management_type_id.name', '=', '押金'),
|
||||
('deposit_state', '=', '已收'),
|
||||
('deposit_state', 'in', ['paid', 'no_paid']),
|
||||
('is_invalid', '=', False),
|
||||
('payout_date', '>=', month_first),
|
||||
('payout_date', '<=', month_last),
|
||||
@@ -50,7 +50,8 @@ class DepositMonthReceivedReport(models.Model):
|
||||
if company_id:
|
||||
domain.append(('company_id', '=', company_id))
|
||||
|
||||
lines = self.sudo().search(domain, order="contract_id asc")
|
||||
# 使用 property.accounts.receivable 模型查询
|
||||
lines = self.env['property.accounts.receivable'].sudo().search(domain, order="contract_id asc")
|
||||
|
||||
rows = []
|
||||
total_amount = 0.0
|
||||
|
||||
@@ -12,7 +12,7 @@ class DepositMonthRefundReport(models.Model):
|
||||
"""
|
||||
押金本月已退报表:
|
||||
- 数据源:property.bills.list
|
||||
- 管理费用类型为"押金"
|
||||
- 管理费用类型为"押金"(management_type_id关联的记录name为"押金")
|
||||
- actual_date有值且在查询月内
|
||||
"""
|
||||
date_start = params.get("date_start")
|
||||
@@ -21,13 +21,22 @@ class DepositMonthRefundReport(models.Model):
|
||||
last_day = calendar.monthrange(query_date.year, query_date.month)[1]
|
||||
month_last = query_date.replace(day=last_day)
|
||||
|
||||
# 获取押金类型的ID
|
||||
deposit_type = self.env['yuthon.management.type'].search([('name', '=', '押金')], limit=1)
|
||||
|
||||
domain = [
|
||||
('management_type_id.name', '=', '押金'),
|
||||
('actual_date', '!=', False),
|
||||
('actual_date', '>=', month_first),
|
||||
('actual_date', '<=', month_last),
|
||||
]
|
||||
|
||||
# 如果找到了押金类型,则添加类型过滤
|
||||
if deposit_type:
|
||||
domain.append(('management_type_id', '=', deposit_type.id))
|
||||
else:
|
||||
# 如果没找到押金类型,用name匹配作为备选
|
||||
domain.append(('management_type_id.name', '=', '押金'))
|
||||
|
||||
keyword = params.get("keyword")
|
||||
if keyword:
|
||||
domain += ['|', '|',
|
||||
@@ -38,13 +47,10 @@ class DepositMonthRefundReport(models.Model):
|
||||
|
||||
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")
|
||||
|
||||
@@ -82,12 +88,6 @@ class DepositMonthRefundReport(models.Model):
|
||||
'display_name': rec.lessee_id.name,
|
||||
} if rec.lessee_id else "",
|
||||
"金额": amount,
|
||||
"所属公司": 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 = [
|
||||
|
||||
@@ -1,93 +1,88 @@
|
||||
import datetime
|
||||
import calendar
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class DepositPreReceivedReport(models.Model):
|
||||
_inherit = 'receivable.modify.line'
|
||||
_inherit = 'property.accounts.receivable'
|
||||
|
||||
@api.model
|
||||
def get_deposit_pre_received_report(self, params):
|
||||
"""
|
||||
押金前期实收报表(数据源:receivable.modify.line):
|
||||
- 应收类型为"押金"
|
||||
- 收款日期(reconciliation_date)在查询日期之前(不含查询月)
|
||||
- 金额取收款记录的 amount,按应收账单聚合
|
||||
押金前期实收报表:
|
||||
- 数据源: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()
|
||||
|
||||
# 前期范围:收款日期 < 查询月月初
|
||||
cutoff_date = query_date.replace(day=1)
|
||||
month_first = query_date.replace(day=1)
|
||||
|
||||
domain = [
|
||||
('reconciliation_date', '!=', False),
|
||||
('reconciliation_date', '<', cutoff_date),
|
||||
('receivable_id.is_invalid', '=', False),
|
||||
('receivable_id.management_type_id.name', '=', '押金'),
|
||||
('management_type_id.name', '=', '押金'),
|
||||
('deposit_state', '=', 'paid'),
|
||||
('is_invalid', '=', False),
|
||||
('payout_date', '!=', False),
|
||||
('payout_date', '<', month_first),
|
||||
]
|
||||
|
||||
keyword = params.get("keyword")
|
||||
if keyword:
|
||||
domain += ['|', '|',
|
||||
('receivable_id.contract_id.contract_code', 'ilike', keyword),
|
||||
('receivable_id.property_name', 'ilike', keyword),
|
||||
('receivable_id.lessee_id.name', 'ilike', keyword),
|
||||
('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')
|
||||
property_id = params.get('property_id')
|
||||
lessee_id = params.get('lessee_id')
|
||||
contract_id = params.get('contract_id')
|
||||
|
||||
if condition:
|
||||
domain.append(('receivable_id.tenure_type', '=', condition))
|
||||
domain.append(('tenure_type', '=', condition))
|
||||
if partner_id:
|
||||
domain.append(('receivable_id.precinct_id', '=', partner_id))
|
||||
domain.append(('precinct_id', '=', partner_id))
|
||||
if company_id:
|
||||
domain.append(('receivable_id.company_id', '=', company_id))
|
||||
if property_id:
|
||||
domain.append(('receivable_id.property_ids', 'in', [property_id]))
|
||||
if lessee_id:
|
||||
domain.append(('receivable_id.lessee_id', '=', lessee_id))
|
||||
if contract_id:
|
||||
domain.append(('receivable_id.contract_id', '=', contract_id))
|
||||
domain.append(('company_id', '=', company_id))
|
||||
|
||||
lines = self.sudo().search(domain, order="receivable_id asc, reconciliation_date asc")
|
||||
|
||||
# 按应收账单聚合
|
||||
rec_map = {}
|
||||
for line in lines:
|
||||
rid = line.receivable_id.id
|
||||
if rid not in rec_map:
|
||||
rec_map[rid] = {'rec': line.receivable_id, 'amount': 0.0}
|
||||
rec_map[rid]['amount'] += line.amount or 0.0
|
||||
lines = self.sudo().search(domain, order="contract_id asc")
|
||||
|
||||
rows = []
|
||||
total_amount = 0.0
|
||||
for idx, (rid, data) in enumerate(rec_map.items(), start=1):
|
||||
rec = data['rec']
|
||||
amount = round(data['amount'], 2)
|
||||
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': rec.contract_id.id,
|
||||
'display_name': rec.contract_id.contract_code,
|
||||
} if rec.contract_id 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 "",
|
||||
'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,
|
||||
"所属公司": rec.company_id.name if rec.company_id else "",
|
||||
"管理员": {
|
||||
|
||||
@@ -35,7 +35,7 @@ class DepositTotalReport(models.Model):
|
||||
|
||||
domain = [
|
||||
('management_type_id.name', '=', '押金'),
|
||||
('deposit_state', '=', '已收'),
|
||||
('deposit_state', '=', 'paid'),
|
||||
('is_invalid', '=', False),
|
||||
('payout_date', '>=', month_first),
|
||||
('payout_date', '<=', month_last),
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "receivable.modify.line",
|
||||
"model": "property.accounts.receivable",
|
||||
"method": "get_deposit_pre_received_report",
|
||||
"dateMode": "single",
|
||||
"columns": [
|
||||
@@ -56,7 +56,7 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "receivable.modify.line",
|
||||
"model": "property.accounts.receivable",
|
||||
"method": "get_deposit_month_received_report",
|
||||
"dateMode": "single",
|
||||
"columns": [
|
||||
@@ -81,7 +81,7 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "receivable.modify.line",
|
||||
"model": "property.accounts.receivable",
|
||||
"method": "get_deposit_cum_arrears_report",
|
||||
"columns": [
|
||||
{"headerName": "序号", "field": "序号", "width": 45, "flex": 0, "pinned": "left"},
|
||||
@@ -104,7 +104,7 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "receivable.modify.line",
|
||||
"model": "property.bills.list",
|
||||
"method": "get_deposit_month_refund_report",
|
||||
"columns": [
|
||||
{"headerName": "序号", "field": "序号", "width": 45, "flex": 0, "pinned": "left"},
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "receivable.modify.line",
|
||||
"model": "property.accounts.receivable",
|
||||
"method": "get_deposit_total_report",
|
||||
"columns": [
|
||||
{"headerName": "序号", "field": "序号", "width": 45, "flex": 0, "pinned": "left"},
|
||||
|
||||
Reference in New Issue
Block a user