diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 20f978231..838b6860a 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -230,7 +230,7 @@ class YuthonVacationReports(models.Model): elif related_model.hours: total_leave_days += float(related_model.hours) / 8 - actual_attendance = actual_attendance - total_leave_days - is_abnormal + actual_attendance = actual_attendance - total_leave_days - is_abnormal month_start = date(year, month, 1) month_end = date(year, month, calendar.monthrange(year, month)[1]) diff --git a/yuthon_property/models/yuthon_property.py b/yuthon_property/models/yuthon_property.py index 1e18895c3..e1e4f9448 100644 --- a/yuthon_property/models/yuthon_property.py +++ b/yuthon_property/models/yuthon_property.py @@ -21,7 +21,8 @@ class YuthonProperty(models.Model): building_area = fields.Float(string="建筑面积", digits=(16, 4)) title_deed = fields.Char(string="产权证号", compute="_compute_title_information_fields", store=True) - effective_date = fields.Date(string="生效日期") + effective_date = fields.Date(string="生效日期", compute="compute_information_fields", store=True) + end_date = fields.Date(string="失效日期", compute="compute_information_fields", store=True) property_source = fields.Selection([('cut', '划入'), ('self', '自建'), ('replace', '置换'), ('buy', '购入'), ('entrust', '委托'), ('Rent', '租入')], string='资产来源') @@ -162,10 +163,11 @@ class YuthonProperty(models.Model): lambda info: info.start_time <= current_date and (not info.end_date or info.end_date >= current_date) ) - if valid_info: current_info = valid_info[0] rec.update({ + 'effective_date': current_info.start_time, + 'end_date': current_info.end_date, 'purpose_id': current_info.purpose_id, 'precinct_id': current_info.precinct_id, 'tenure_type': current_info.tenure_type, diff --git a/yuthon_report/models/ledger_report.py b/yuthon_report/models/ledger_report.py index a5b948ab8..f76e3a698 100644 --- a/yuthon_report/models/ledger_report.py +++ b/yuthon_report/models/ledger_report.py @@ -15,12 +15,12 @@ class YuthonProperty(models.Model): ) - # if params.get("date_start"): - # date_start = datetime.datetime.fromisoformat(params.get("date_start")).date() - # domain.append(("actual_start_time", ">=", date_start)) - # if params.get("date_end"): - # date_end = datetime.datetime.fromisoformat(params.get("date_start")).date() - # domain.append(("actual_end_time", "<=", date_end)) + if params.get("date_start"): + date_start = datetime.datetime.fromisoformat(params.get("date_start")).date() + domain.append(("effective_date", ">=", date_start)) + if params.get("date_end"): + date_end = datetime.datetime.fromisoformat(params.get("date_start")).date() + domain.append(("end_date", "<=", date_end)) condition = params.get('condition',False) @@ -40,34 +40,83 @@ class YuthonProperty(models.Model): properties = self.search(domain, limit=100) state_selection = dict(self._fields['property_state']._description_selection(self.env)) - return [ - { + cycle_convert = { + 'monthly': 1, + 'quarter': 4, + 'half': 6, + 'year': 12 + } + + result = [] + for p in properties: + # 1. 筛选符合日期范围的合同:property_contract_ids中满足周期交集的记录 + filtered_contracts = p.property_contract_ids.filtered( + lambda contract: + contract.start_time and + (not contract.end_time or contract.end_time >= date_start) and + contract.start_time <= (date_end or datetime.max.date()) + ) + + # 2. 处理筛选后的合同 + target_contract = filtered_contracts if filtered_contracts else False + # 3. 获取合同信息 + rent_company = target_contract.rent_company if target_contract else "" + lessee_id = target_contract.lessee_id.name if (target_contract and target_contract.lessee_id) else "" + property_name = target_contract.property_name if target_contract else "" + contact = target_contract.lessee_id.contact if (target_contract and target_contract.lessee_id) else "" + rental_purposes = target_contract.rental_purposes if target_contract else "" + contract_code = target_contract.contract_code if target_contract else "" + total_area = target_contract.total_area if target_contract else 0.0 + first_year_rent = target_contract.first_year_rent if target_contract else 0.0 + contract_date = target_contract.contract_date.strftime("%Y-%m-%d") if ( + target_contract and target_contract.contract_date) else "" + term_start_time = target_contract.term_start_time.strftime("%Y-%m-%d") if ( + target_contract and target_contract.term_start_time) else "" + term_end_time = target_contract.term_end_time.strftime("%Y-%m-%d") if ( + target_contract and target_contract.term_end_time) else "" + unit_price = target_contract.unit_price if target_contract else 0.0 + total_contract_receivables = target_contract.total_contract_receivables if target_contract else 0.0 + total_receivable = target_contract.total_receivable if target_contract else 0.0 + + # 4. 计算月租金 + rent = target_contract.rent if target_contract else 0.0 + cycle = target_contract.cycle_dict if (target_contract and target_contract.cycle_dict) else 'monthly' + monthly_rent = rent / cycle_convert.get(cycle, 1) if cycle_convert.get(cycle, 1) != 0 else 0.0 + + # 5. 从property.lease.contract.line提取评估单价(按address_id匹配) + evaluate_unit_price = 0.0 + if target_contract: + lease_line = self.env['property.lease.contract.line'].search([ + ('address_id', '=', p.id), # 按资产ID匹配明细行 + ('lease_contract_id', '=', target_contract.id) # 按目标合同匹配 + ], limit=1) + evaluate_unit_price = lease_line.evaluate_unit_price if lease_line else 0.0 + + # 6. 组装当前资产的结果 + result.append({ "资产地址": p.name or "", "资产面积": p.equity_area or 0.0, "街道": p.street or "", - "小区": p.precinct_id.name or "" if p.precinct_id else "", - "证载用途": p.registered_id.name or "" if p.registered_id else "", + "小区": p.precinct_id.name if (p.precinct_id) else "", + "证载用途": p.registered_id.name if (p.registered_id) else "", "资产目前状态": state_selection.get(p.property_state, ""), - "片区管理员": p.admin_id.name or "" if p.admin_id else "", - "出租单位": p.property_contract_ids.lease_contract_id.lessor_id.name or "" - if p.property_contract_ids and p.property_contract_ids.lease_contract_id.lessor_id else "", - "承租方": p.lessee_id.name or "" if p.lessee_id else "", - "出租地址": p.rental_address or "", - "联系人": "p.contact "or "", - "出租用途": p.property_contract_ids[0].lease_contract_id.rental_purposes.name or "" - if p.property_contract_ids and p.property_contract_ids.lease_contract_id.rental_purposes else "", - "审批情况": "p.approval_status "or "", - # "租赁合同号": p.contract_id.name or "" if "p.contract_id" else "", - "出租面积": "p.rental_area "or 0.0, - "评估价(元/m² •月)": "p.appraisal_price" or 0.0, - # "首年租金": p.first_year_rent or 0.0, - # "合同签订日期": p.contract_date.strftime("%Y-%m-%d") if "p.contract_date" else "", - # "合约开始时间": p.term_start_time.strftime("%Y-%m-%d") if "p.term_start_time" else "", - # "合约结束时间": p.term_end_time.strftime("%Y-%m-%d") if "p.term_end_time" else "", - "单价": p.unit_price or 0.0, - # "月租金": p.monthly_amount or 0.0, - # "合同总金额": p.total_amount or 0.0, - # "实际已收到金额": p.real_amount or 0.0 - } - for p in properties - ] \ No newline at end of file + "片区管理员": p.admin_id.name if (p.admin_id) else "", + "出租单位": rent_company, + "承租方": lessee_id, + "出租地址": property_name, + "联系人": contact, + "出租用途": rental_purposes, + "审批情况": p.approval_status or "", + "租赁合同号": contract_code, + "出租面积": total_area, + "评估价(元/m² •月)": evaluate_unit_price, + "首年租金": first_year_rent, + "合同签订日期": contract_date, + "合约开始时间": term_start_time, + "合约结束时间": term_end_time, + "合同总金额": total_contract_receivables, + "单价": unit_price, + "月租金": monthly_rent, + "实际已收到金额": total_receivable + }) + return result \ No newline at end of file