Files
gzth/yuthon_report/models/receivable_report.py
T
2026-03-02 22:14:23 +08:00

113 lines
4.5 KiB
Python

import datetime
from odoo import fields, models, api
class YuthonProperty(models.Model):
_inherit = 'property.accounts.receivable'
@api.model
def get_complete_ledger_report(self, params):
domain = []
if params.get("keyword"):
keyword = params["keyword"]
domain += [
'|', '|',
('lessee_id.name', 'ilike', keyword),
('property_name', 'ilike', keyword),
('title_deed', 'ilike', keyword)
]
if params.get("date_start"):
date_start = datetime.datetime.fromisoformat(params.get("date_start")).date()
domain.append(("due_date", ">=", date_start))
if params.get("date_end"):
date_end = datetime.datetime.fromisoformat(params.get("date_end")).date()
domain.append(("due_date", "<=", date_end))
# condition, 这里需要放到具体的搜索条件中 domain .
condition = params.get('condition', False)
partner_id = params.get('partner_id', False)
company_id = params.get('company_id', False)
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)
management_type_map = dict(
self.env['yuthon.management.type'].search([]).mapped(lambda r: (r.id, r.name))
)
invoice_type_map = dict(
self._fields['invoice_type']._description_selection(self.env)
)
rows = []
type_totals = {}
total_amount = 0.0
for idx, rec in enumerate(receivables, start=1):
mgmt_type = management_type_map.get(rec.management_type_id.id, "") if rec.management_type_id else "未分类"
amount = rec.original_amount or 0.0
total_amount += amount
if mgmt_type not in type_totals:
type_totals[mgmt_type] = {'amount': 0.0}
type_totals[mgmt_type]['amount'] += amount
rows.append({
"序号": idx,
"应收类型": mgmt_type,
"应收开始": rec.due_date.strftime("%Y-%m-%d") if rec.due_date else "",
"应收结束": rec.due_date_end.strftime("%Y-%m-%d") if rec.due_date_end else "",
"当期金额": round(amount, 2),
"合同编号": {
'model': 'property.lease.contract',
'id': rec.contract_id.id,
'display_name': rec.contract_id.contract_code,
} if rec.contract_id else "",
"承租方": {
'model': 'property.tenant.information',
'id': rec.lessee_id.id,
'display_name': rec.lessee_id.name,
} if rec.lessee_id else "",
"物业名称": rec.property_name or "",
"产权证号": rec.title_deed or "",
"发票类型": rec.lessee_id.invoicing_ids[0].invoicing_type_id.name if rec.lessee_id and rec.lessee_id.invoicing_ids else "",
"税率": (
lambda tr: (
lambda v: f"{v:.1f}%" if v is not None else "0.0%"
)(
float(str(tr).replace('%', '').strip())
if tr and str(tr).replace('%', '').strip()
else None
)
)(rec.contract_id.tax_rate.name if rec.contract_id and rec.contract_id.tax_rate else None)
})
summary_stats = []
for type_name in sorted(type_totals.keys()):
summary_stats.append({'name': type_name, 'amount': round(type_totals[type_name]['amount'], 2)})
summary_stats.append({'name': '总合计', 'amount': round(total_amount, 2)})
return {"rows": rows, "stats": summary_stats}
@api.model
def get_domain(self, start_date=False, end_date=False, company_id=False):
if not start_date or not end_date:
return []
if not company_id:
return []
# 这里进行条件的修改
property_records = self.env['yuthon.property'].search([('company_id', '=', company_id)])
user_ids = set()
for property_record in property_records:
user_ids.add(property_record.precinct_id.id)
return list(user_ids)