93 lines
3.6 KiB
Python
93 lines
3.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
from .report_utils import _id_list
|
|
from odoo import api, models
|
|
|
|
|
|
class BankStatementsReport(models.Model):
|
|
_name = 'bank.statements.report'
|
|
_description = '未对挂账报表'
|
|
|
|
@api.model
|
|
def get_bank_statements_report(self, params):
|
|
"""
|
|
"未对挂账报表(数据源:property.bank.statements):"
|
|
- bank_state 字段值是'挂账'和'未对账'的
|
|
- 字段:交易时间、交易金额、已对账、未对、备注、摘要、对方户名、账号单位、状态
|
|
- 搜索条件:公司
|
|
"""
|
|
domain = []
|
|
|
|
# 过滤 bank_state 为 '挂账' 和 '未对账'
|
|
domain.append(('bank_state', 'in', ['not_reconciled', 'registered']))
|
|
|
|
# 过滤 lending_direction 为 'loan' (贷方)
|
|
domain.append(('lending_direction', '=', 'loan'))
|
|
|
|
# 公司搜索条件
|
|
company_id = _id_list(params.get('company_id'))
|
|
if company_id:
|
|
domain.append(('company_id', 'in', company_id))
|
|
|
|
# 账号单位搜索条件
|
|
your_own_unit = params.get('your_own_unit')
|
|
if your_own_unit and isinstance(your_own_unit, str) and your_own_unit.strip():
|
|
domain.append(('your_own_unit', 'ilike', your_own_unit.strip()))
|
|
|
|
# 搜索关键字
|
|
keyword = params.get('keyword')
|
|
if keyword and isinstance(keyword, str) and keyword.strip():
|
|
domain += [
|
|
'|', '|', '|', '|', '|', '|', '|',
|
|
('name_account', 'ilike', keyword.strip()),
|
|
('name', 'ilike', keyword.strip()),
|
|
('your_own_account', 'ilike', keyword.strip()),
|
|
('your_own_unit', 'ilike', keyword.strip()),
|
|
('extract', 'ilike', keyword.strip()),
|
|
('remake', 'ilike', keyword.strip()),
|
|
('serial_number', 'ilike', keyword.strip()),
|
|
]
|
|
|
|
# 搜索数据
|
|
lines = self.env['property.bank.statements'].sudo().search(domain, order="start_time desc")
|
|
|
|
rows = []
|
|
total_amount = 0.0
|
|
for idx, line in enumerate(lines, start=1):
|
|
amount = round(line.original_amount or 0.0, 2)
|
|
total_amount += amount
|
|
|
|
rows.append({
|
|
"序号": idx,
|
|
"交易时间": line.start_time.strftime('%Y-%m-%d %H:%M:%S') if line.start_time else '',
|
|
"交易金额": amount,
|
|
"已对账": round(line.yes_amount or 0.0, 2),
|
|
"未对": round(line.no_amount or 0.0, 2),
|
|
"备注": line.remake or '',
|
|
"摘要": line.extract or '',
|
|
"对方户名": line.name_account or '',
|
|
"账号单位": line.your_own_unit or '',
|
|
"状态": dict(line._fields['bank_state'].selection).get(line.bank_state, line.bank_state),
|
|
})
|
|
|
|
stats = [
|
|
{'name': '记录总数', 'amount': len(rows)},
|
|
{'name': '交易总金额', 'amount': round(total_amount, 2)},
|
|
]
|
|
|
|
return {"rows": rows, "stats": stats}
|
|
|
|
@api.model
|
|
def get_your_own_unit_options(self):
|
|
"""获取账号单位选项列表"""
|
|
# 使用 distinct 获取唯一的账号单位值
|
|
self.env.cr.execute("""
|
|
SELECT DISTINCT your_own_unit
|
|
FROM property_bank_statements
|
|
WHERE bank_state IN ('not_reconciled', 'registered')
|
|
AND your_own_unit IS NOT NULL
|
|
AND your_own_unit != ''
|
|
ORDER BY your_own_unit
|
|
""")
|
|
results = self.env.cr.fetchall()
|
|
return [{'label': row[0], 'value': row[0]} for row in results]
|