报表
This commit is contained in:
@@ -5,53 +5,78 @@ from odoo import api, models
|
||||
|
||||
|
||||
class MonthReceivableReport(models.Model):
|
||||
_inherit = 'property.accounts.receivable'
|
||||
_inherit = 'receivable.modify.line'
|
||||
|
||||
@api.model
|
||||
def get_month_receivable_report(self, params):
|
||||
"""本月应收:取 due_date <= 查询月底 且 submitted > 0 的记录"""
|
||||
domain = [('is_invalid', '=', False), ('submitted', '>', 0)]
|
||||
"""本月应收(数据源:receivable.modify.line):
|
||||
- receivable_id.due_date <= 查询月底
|
||||
- receivable_id.submitted > 0(有未收金额)
|
||||
- receivable_id.is_invalid = False
|
||||
- 排除押金和违约金
|
||||
- 金额取 original_amount(交易金额)
|
||||
"""
|
||||
domain = [
|
||||
('receivable_id.is_invalid', '=', False),
|
||||
('receivable_id.submitted', '>', 0),
|
||||
('receivable_id.management_type_id.name', 'not in', ['押金', '违约金']),
|
||||
]
|
||||
|
||||
# 单月日期选择器传 date_start
|
||||
if params.get('date_start'):
|
||||
query_date = datetime.datetime.fromisoformat(params['date_start']).date()
|
||||
last_day = calendar.monthrange(query_date.year, query_date.month)[1]
|
||||
month_end = query_date.replace(day=last_day)
|
||||
domain.append(('due_date', '<=', month_end))
|
||||
domain.append(('receivable_id.due_date', '<=', month_end))
|
||||
|
||||
if params.get('keyword'):
|
||||
keyword = params['keyword']
|
||||
domain += ['|', '|',
|
||||
('lessee_id.name', 'ilike', keyword),
|
||||
('property_name', 'ilike', keyword),
|
||||
('contract_id.contract_code', 'ilike', keyword)]
|
||||
('receivable_id.lessee_id.name', 'ilike', keyword),
|
||||
('receivable_id.property_name', 'ilike', keyword),
|
||||
('receivable_id.contract_id.contract_code', 'ilike', keyword)]
|
||||
|
||||
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):
|
||||
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,
|
||||
'合同编号': {
|
||||
'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 '',
|
||||
'承租方名称': rec.lessee_id.name if rec.lessee_id else '',
|
||||
'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 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 = [{'name': '合计', 'amount': round(total_amount, 2)}]
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "property.accounts.receivable",
|
||||
"model": "receivable.modify.line",
|
||||
"method": "get_month_receivable_report",
|
||||
"dateMode": "single",
|
||||
"columns": [
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "property.accounts.receivable",
|
||||
"model": "receivable.modify.line",
|
||||
"method": "get_pre_advance_report",
|
||||
"dateMode": "single",
|
||||
"columns": [
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "property.accounts.receivable",
|
||||
"model": "receivable.modify.line",
|
||||
"method": "get_pre_arrears_report",
|
||||
"dateMode": "single",
|
||||
"columns": [
|
||||
|
||||
Reference in New Issue
Block a user