From 8788ae280088b8082d688088fb0f0e0e89d80448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Mon, 3 Nov 2025 15:20:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/property_meter_archives.py | 2 +- .../models/property_meter_water.py | 2 +- yuthon_property/wizard/meter_price_wizard.py | 28 ++++++----- .../wizard/property_statements_wizard.py | 22 --------- yuthon_property/wizard/water_price_wizard.py | 23 +++++---- .../models/property_lease_contract.py | 33 +++++++------ .../models/property_lease_renewal.py | 49 ++++++++++++++++++- .../security/ir.model.access.csv | 4 +- .../views/property_lease_contract.xml | 32 +++++++----- .../views/property_lease_renewal.xml | 5 +- 10 files changed, 121 insertions(+), 79 deletions(-) diff --git a/yuthon_property/models/property_meter_archives.py b/yuthon_property/models/property_meter_archives.py index 82c79fae9..364a4a4f3 100644 --- a/yuthon_property/models/property_meter_archives.py +++ b/yuthon_property/models/property_meter_archives.py @@ -269,7 +269,7 @@ class MeterArchivesLine(models.Model): else: record.current_meter = 0 - @api.onchange('current_meter', 'unit') + @api.onchange('current_meter', 'unit', 'line_loss') def onchange_receivables(self): for record in self: # 因为current_meter 取不到值所有复制一遍 diff --git a/yuthon_property/models/property_meter_water.py b/yuthon_property/models/property_meter_water.py index 3e7febb28..505ab6fbe 100644 --- a/yuthon_property/models/property_meter_water.py +++ b/yuthon_property/models/property_meter_water.py @@ -238,7 +238,7 @@ class MeterWaterLine(models.Model): else: rec.meter_date_month = False - @api.onchange('current_meter', 'unit') + @api.onchange('current_meter', 'unit', 'line_loss') def onchange_receivables(self): for record in self: # 因为current_meter 取不到值所有复制一遍 diff --git a/yuthon_property/wizard/meter_price_wizard.py b/yuthon_property/wizard/meter_price_wizard.py index 7669c1bb8..4b084aa11 100644 --- a/yuthon_property/wizard/meter_price_wizard.py +++ b/yuthon_property/wizard/meter_price_wizard.py @@ -29,35 +29,37 @@ class MeterPriceWizard(models.TransientModel): ]) for valid in valid_contract_lines: if valid.archives_id.type == 'fees': - if valid.yuthon_property_ids: - contract_id = self.env['property.contract.line'].search([ - ('yuthon_property_id', '=', valid.yuthon_property_ids[0].id), - ('start_time', '<=', self.price_date), - ('end_date', '>=', self.price_date), - ], limit=1) - if contract_id: - if contract_id.lease_contract_id.ele_price > 0: - unit = contract_id.lease_contract_id.ele_price + if valid.contract_id.id: + electric_id = self.env['property.electric.fee.line'].search([ + ('property_meter_archives_id.name', '=', '950404861125'), + ('contract_id', '=', valid.contract_id.id), + ]) + if electric_id: + if electric_id.unit_price > 0: + unit = electric_id.unit_price + line_loss = electric_id.line_loss if electric_id.line_loss > 0 else self.line_loss else: unit = self.price + line_loss = self.line_loss else: unit = self.price + line_loss = self.line_loss else: unit = self.price + line_loss = self.line_loss else: unit = 0 + line_loss = 0 valid.write({ 'unit': unit, 'meter_date': self.price_date, - 'line_loss': self.line_loss + 'line_loss': line_loss }) self.env['hydropower.logs'].create({ 'meter_type': 'electric', 'logs_date': self.price_date, 'price': self.price, - 'line_loss': self.line_loss, + 'line_loss':self.line_loss, }) - - diff --git a/yuthon_property/wizard/property_statements_wizard.py b/yuthon_property/wizard/property_statements_wizard.py index 811d9cac8..6f2b1e138 100644 --- a/yuthon_property/wizard/property_statements_wizard.py +++ b/yuthon_property/wizard/property_statements_wizard.py @@ -99,28 +99,6 @@ class PropertyStatementsWizard(models.Model): elif original_amount: self.env['property.bank.statements'].create(bank_data) - def _handle_contract_penalty(self, record): - ''' - 处理合同违约金 - :param record: property.bank.statements 记录 - :return: - ''' - for contract_id in record.contract_ids: - receivable_id = self.env['property.accounts.receivable'].search([('contract_id', '=', contract_id.id)]) - if receivable_id: - dt = datetime.strptime(str(record.start_time), '%Y-%m-%d %H:%M:%S').date() # 流水交易时间 - due = datetime.strptime(str(receivable_id.due_date), '%Y-%m-%d').date() + relativedelta(months=1, day=1) # 应收日期 - # 判断是否违约 - if receivable_id.submitted and not receivable_id.is_reconciliation or not receivable_id.is_suspend: - original_amount = (due - dt).days * receivable_id.original_amount * int(receivable_id.percentage_liquidated_damages.name) - self.env['property.penalty.list'].create({ - 'contract_id': contract_id.id, - 'property_id': contract_id.lease_ids[0].address_id.id, - 'lessee_id': contract_id.lessee_id.id, - 'original_amount': original_amount - }) - receivable_id.write({'penalty':original_amount}) - receivable_id.is_reconciliation = True def classify_by_last_four(self, input_str): if not isinstance(input_str, str) or len(input_str) < 4: diff --git a/yuthon_property/wizard/water_price_wizard.py b/yuthon_property/wizard/water_price_wizard.py index 242e13cfb..f25b98de3 100644 --- a/yuthon_property/wizard/water_price_wizard.py +++ b/yuthon_property/wizard/water_price_wizard.py @@ -29,28 +29,31 @@ class WaterPriceWizard(models.TransientModel): ]) for valid in valid_contract_lines: if valid.water_id.type == 'fees': - if valid.yuthon_property_ids: - contract_id = self.env['property.contract.line'].search([ - ('yuthon_property_id', '=', valid.yuthon_property_ids[0].id), - ('start_time', '<=', self.price_date), - ('end_date', '>=', self.price_date), - ], limit=1) - if contract_id: - if contract_id.lease_contract_id.water_price > 0: - unit = contract_id.lease_contract_id.water_price + if valid.contract_id.id: + water_id = self.env['property.water.fee.line'].search([ + ('property_meter_water_id', '=', valid.water_id.id), + ]) + if water_id: + if water_id.unit_price > 0: + unit = water_id.unit_price + line_loss = water_id.line_loss if water_id.line_loss > 0 else self.line_loss else: unit = self.price + line_loss = self.line_loss else: unit = self.price + line_loss = self.line_loss else: unit = self.price + line_loss = self.line_loss else: unit = 0 + line_loss = 0 valid.write({ 'unit': unit, 'meter_date': self.price_date, - 'line_loss': self.line_loss + 'line_loss': line_loss, }) self.env['hydropower.logs'].create({ diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index 145027415..cc4116021 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -93,6 +93,7 @@ class PropertyLeaseContract(models.Model): _rec_name = 'contract_code' property_name = fields.Char(string='物业信息') + version = fields.Char(string="合同版本", default="V1.0") code = fields.Char(string="流水号", default=lambda self: self.env['ir.sequence'].next_by_code('property_lease_contract_code')) admin_id = fields.Many2one('res.users', string="管理员", compute="_compute_admin_id", store=True) tenure_type = fields.Selection([('self', '自有'), ('agency', '代管')], string='权属类型', compute="_compute_admin_id", store=True) @@ -191,12 +192,10 @@ class PropertyLeaseContract(models.Model): use_address = fields.Char(string="财务专用地址") not_tax_amount = fields.Float(string="不含税价") tax = fields.Float(string="税金") - is_water = fields.Boolean(string="是否有水费", compute='_compute_lease_ids') - is_electricity = fields.Boolean(string="是否有电费", compute='_compute_lease_ids') + is_water = fields.Boolean(string="是否有水费") + is_electricity = fields.Boolean(string="是否有电费") is_manage = fields.Boolean(string="是否有管理费", compute='compute_is_manage') miscellaneous = fields.Text(string="其他约定") - water_price = fields.Float(string="水费单价") - ele_price = fields.Float(string="电费单价") number = fields.Integer(string="次数", default=0) total_area = fields.Float(string="总面积", digits=(16, 4)) not_received = fields.Float(string="未收", compute="_compute_contract_count") @@ -219,8 +218,8 @@ class PropertyLeaseContract(models.Model): ele_breakdown_ids = fields.One2many('property.ele.breakdown.line', 'breakdown_id', string="物业电费明细行") management_breakdown_ids = fields.One2many('property.management.breakdown.line', 'breakdown_id', string="物业管理费明细行") - water_fee_ids = fields.One2many('property.water.fee.line', 'contract_id', string="物业水表明细行", compute='_compute_lease_ids', store=True) - electricity_fee_ids = fields.One2many('property.electric.fee.line', 'contract_id', string="物业电表明细行", compute='_compute_lease_ids', store=True) + water_fee_ids = fields.One2many('property.water.fee.line', 'contract_id', string="物业水表明细行") + electricity_fee_ids = fields.One2many('property.electric.fee.line', 'contract_id', string="物业电表明细行") mange_fee_ids = fields.One2many('property.manage.fee.line', 'contract_id', string="物业管理费明细行", store=True) # 不需要 other_ids = fields.One2many('property.other.fee.line', 'other_id', string="其他费用明细行") lease_bank_ids = fields.One2many('property.bank.line', 'contract_id', string="承租方账户明细行") @@ -478,10 +477,10 @@ class PropertyLeaseContract(models.Model): self._context.get('active_ids', self._context.get('active_id'))) for rec in contract_ids: if rec.lease_ids: - rec.admin_id = rec.lease_ids[0].admin_line_id.id + rec.onchange_lease_ids() - @api.depends("lease_ids") - def _compute_lease_ids(self): + @api.onchange("lease_ids") + def onchange_lease_ids(self): for rec in self: # 初始化值 rec.is_water = False @@ -519,6 +518,7 @@ class PropertyLeaseContract(models.Model): 'contract_id': rec.id, 'property_meter_archives_id': meter.property_meter_archives_id.id, }]) + rec.is_water = bool(water_fee_values) rec.is_electricity = bool(electricity_fee_values) if water_fee_values: @@ -1511,6 +1511,8 @@ class PropertyLeaseContract(models.Model): existing_records = self.search([ ('id', '!=', record.id), ('contract_code', '!=', False), + ('version', '=', record.version), + ('contract_type', '=', record.contract_type), ]) for existing in existing_records: if self._normalize_contract_code(existing.contract_code) == normalized_code: @@ -1673,8 +1675,7 @@ class PropertyLeaseContract(models.Model): contract_id.write({ 'lease_ids': lease_list, 'other_ids': other_list,}) - # 'management_list_ids':management_list,}) - + contract_id.onchange_lease_ids() return { 'type': 'ir.actions.client', 'tag': 'display_notification', @@ -1867,7 +1868,7 @@ class PropertyLeaseContract(models.Model): 'name': '续期合同', 'res_model': 'property.lease.contract', 'view_mode': 'form', - 'res_id': new_contract.id, # 指定新合同的ID + 'res_id': new_contract.id, 'target': 'current', } @@ -2047,7 +2048,7 @@ class PropertyManagementBreakdownLine(models.Model): class PropertyWaterFeeLine(models.Model): _name = 'property.water.fee.line' - _description = '物业水费明细行' + _description = '物业水表库明细行' contract_id = fields.Many2one('property.lease.contract', string="关联租赁合同审批") property_meter_water_id = fields.Many2one('property.meter.water', string="水表库") @@ -2055,12 +2056,14 @@ class PropertyWaterFeeLine(models.Model): unit_number = fields.Char(related='property_meter_water_id.unit_number', string="单元编号/用途", store=True) start_date = fields.Date(related='contract_id.term_start_time', string="开始日期") end_date = fields.Date(related='contract_id.term_end_time', string="结束日期") + unit_price = fields.Float(string='固定单价', digits=(16, 4)) + line_loss = fields.Float(string='线损') epitope_values_id = fields.Many2one(related='property_meter_water_id.epitope_values_id', string="表位置") class PropertyElectricFeeLine(models.Model): _name = 'property.electric.fee.line' - _description = '物业电费明细行' + _description = '物业电表信息明细行' contract_id = fields.Many2one('property.lease.contract', string="关联租赁合同审批") property_meter_archives_id = fields.Many2one('property.meter.archives', string="电表编号") @@ -2068,6 +2071,8 @@ class PropertyElectricFeeLine(models.Model): unit_number = fields.Char(related='property_meter_archives_id.unit_number', string="单元编号/用途", store=True) start_date = fields.Date(related='contract_id.term_start_time', string="开始日期") end_date = fields.Date(related='contract_id.term_end_time', string="结束日期") + unit_price = fields.Float(string='固定单价', digits=(16, 4)) + line_loss = fields.Float(string='线损') epitope_values_id = fields.Many2one(related='property_meter_archives_id.epitope_values_id', string="表位置") diff --git a/yuthon_property_approval/models/property_lease_renewal.py b/yuthon_property_approval/models/property_lease_renewal.py index d17c2f2e1..9082cadc2 100644 --- a/yuthon_property_approval/models/property_lease_renewal.py +++ b/yuthon_property_approval/models/property_lease_renewal.py @@ -16,7 +16,7 @@ class PropertyLeaseRenewal(models.Model): company_id = fields.Many2one(related='user_id.company_id', string="公司") code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('property_lease_renewal_code')) - renewal_type = fields.Selection([('early_checkout', '提前退租'), ('lease', '承租方变更')], string='变更类型') + renewal_type = fields.Selection([('early_checkout', '提前退租'), ('lease', '承租方变更'), ('agreement','补充协议')], string='变更类型') urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度', default='normal') def _get_default_name_title(self): @@ -80,9 +80,54 @@ class PropertyLeaseRenewal(models.Model): 'rent': rec.contract_id.rent, }]) lessee_id.write({'property_contract_ids': property_contract_list}) - else: + elif rec.renewal_type == 'early_checkout': rec.contract_id.write({ 'actual_end_time': rec.early_quitting_date}) + else: + version_str = rec.contract_id.version.lstrip('V') + main_version = version_str.split('.')[0] + new_main_version = int(main_version) + 1 + new_version = f"V{new_main_version}.0" + new_contract = rec.contract_id.with_context(skip_contract_code_check=True).copy() + new_contract.write({ + 'version': new_version + }) + water_lines = self.env['property.water.fee.line'].search([ + ('contract_id', '=', rec.contract_id.id) + ]) + for line in water_lines: + line.copy({'contract_id': new_contract.id}) + # 复制电费明细行 + electric_lines = self.env['property.electric.fee.line'].search([ + ('contract_id', '=', rec.contract_id.id) + ]) + for line in electric_lines: + line.copy({'contract_id': new_contract.id}) + # 复制物业管理费明细行 + manage_lines = self.env['property.manage.fee.line'].search([ + ('contract_id', '=', rec.contract_id.id) + ]) + for line in manage_lines: + line.copy({'contract_id': new_contract.id}) + # 复制其他费用明细行 + other_lines = self.env['property.other.fee.line'].search([ + ('other_id', '=', rec.contract_id.id) + ]) + for line in other_lines: + line.copy({'other_id': new_contract.id}) + # 复制子合同明细 + subset_lines = self.env['property.subset.contract'].search([ + ('subset_id', '=', rec.contract_id.id) + ]) + for line in subset_lines: + line.copy({'subset_id': new_contract.id}) + lease_lines = self.env['property.lease.contract.line'].search([ + ('lease_id', '=', rec.contract_id.id) + ]) + for line in lease_lines: + line.copy({'lease_id': new_contract.id}) + new_contract._compute_name() + rec.contract_id.get_property_contract_time() rec.hide = True diff --git a/yuthon_property_approval/security/ir.model.access.csv b/yuthon_property_approval/security/ir.model.access.csv index 1060ba967..b9358a357 100644 --- a/yuthon_property_approval/security/ir.model.access.csv +++ b/yuthon_property_approval/security/ir.model.access.csv @@ -113,4 +113,6 @@ access_penalty_pay_line, penalty_pay_line,model_penalty_pay_line,base.group_user access_contract_accounts_receivable, contract_accounts_receivable,model_contract_accounts_receivable,base.group_user,1,1,1,1 access_property_water_breakdown_line, property_water_breakdown_line,model_property_water_breakdown_line,base.group_user,1,1,1,1 access_property_ele_breakdown_line, property_ele_breakdown_line,model_property_ele_breakdown_line,base.group_user,1,1,1,1 -access_property_management_breakdown_line, property_management_breakdown_line,model_property_management_breakdown_line,base.group_user,1,1,1,1 \ No newline at end of file +access_property_management_breakdown_line, property_management_breakdown_line,model_property_management_breakdown_line,base.group_user,1,1,1,1 +access_property_electric_fee_line,property_electric_fee_line,model_property_electric_fee_line,base.group_user,1,1,1,1 +access_property_water_fee_line,property_water_fee_line,model_property_water_fee_line,base.group_user,1,1,1,1 diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml index 6e77a8cd6..92836b234 100644 --- a/yuthon_property_approval/views/property_lease_contract.xml +++ b/yuthon_property_approval/views/property_lease_contract.xml @@ -65,6 +65,7 @@
+
@@ -249,8 +250,6 @@ - - @@ -279,13 +278,15 @@ - + + + - + + - @@ -293,12 +294,14 @@ + + - + + - @@ -464,6 +467,7 @@
+
@@ -663,8 +667,6 @@ - - @@ -749,12 +751,14 @@ | + + - + + - @@ -762,12 +766,14 @@ + + - + + - diff --git a/yuthon_property_approval/views/property_lease_renewal.xml b/yuthon_property_approval/views/property_lease_renewal.xml index 12a3210ce..8fb30d4b2 100644 --- a/yuthon_property_approval/views/property_lease_renewal.xml +++ b/yuthon_property_approval/views/property_lease_renewal.xml @@ -44,8 +44,9 @@ + - + @@ -67,7 +68,7 @@ - +