@@ -1,3 +1,4 @@
|
||||
import calendar
|
||||
import datetime
|
||||
|
||||
from odoo import api, models
|
||||
@@ -10,27 +11,33 @@ class CumIncomeReport(models.Model):
|
||||
def get_cum_income_report(self, params):
|
||||
"""
|
||||
累计收入报表(数据源:receivable.modify.line):
|
||||
- 按年查询
|
||||
- 取交易金额(original_amount)
|
||||
- 查询范围:年初(1月1日)到查询月末(非全年)
|
||||
例如查3月 → 1月1日 ~ 3月31日;查6月 → 1月1日 ~ 6月30日
|
||||
- 用 reconciliation_date(收款行对账日期)判断已收
|
||||
- 取每行的 amount(已对金额)
|
||||
- 排除押金和违约金类型
|
||||
"""
|
||||
today = datetime.date.today()
|
||||
current_year = today.year
|
||||
|
||||
date_start = params.get("date_start")
|
||||
# 按年查询:如果有传值则使用该年份,否则使用当前年份
|
||||
# 取查询日所在年份和月份
|
||||
if date_start:
|
||||
year = datetime.datetime.fromisoformat(date_start).year
|
||||
query_date = datetime.datetime.fromisoformat(date_start).date()
|
||||
else:
|
||||
year = current_year
|
||||
query_date = today
|
||||
|
||||
# 构建年份的开始和结束日期
|
||||
year = query_date.year
|
||||
query_month = query_date.month
|
||||
|
||||
# 查询范围:年初到查询月末
|
||||
year_start = datetime.date(year, 1, 1)
|
||||
year_end = datetime.date(year, 12, 31)
|
||||
last_day = calendar.monthrange(year, query_month)[1]
|
||||
query_month_end = datetime.date(year, query_month, last_day)
|
||||
|
||||
# 用 reconciliation_date(收款行自身的对账日期)做时间范围筛选
|
||||
domain = [
|
||||
('receivable_id.due_date', '>=', year_start),
|
||||
('receivable_id.due_date', '<=', year_end),
|
||||
('reconciliation_date', '>=', year_start),
|
||||
('reconciliation_date', '<=', query_month_end),
|
||||
('receivable_id.is_invalid', '!=', True),
|
||||
]
|
||||
|
||||
@@ -66,7 +73,7 @@ class CumIncomeReport(models.Model):
|
||||
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)
|
||||
amount = round(line.amount or 0.0, 2) # 取已对金额(实际收到的钱)
|
||||
total_amount += amount
|
||||
|
||||
# 物业穿透
|
||||
|
||||
Reference in New Issue
Block a user