diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index 5419ae6a5..f4d924c28 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -446,7 +446,6 @@ class PropertyBankStatements(models.Model): "default_bank_id": self.id, "default_bank_branch": self.bank_branch, "default_account": record.name, - "default_remake": self.remake, "default_actual_total": record.original_amount, "default_reconciliation_line_ids": all_vals, # 租金,应收日期排序、管理费、电、水、押金 'default_amount_reconciled': self.no_amount, @@ -454,6 +453,7 @@ class PropertyBankStatements(models.Model): "dialog_size": "extra-large", "default_order": "due_date desc", } + self._check_unreconciled_statements(start_time) return { "type": "ir.actions.act_window", @@ -465,6 +465,34 @@ class PropertyBankStatements(models.Model): "context": context, } + def _check_unreconciled_statements(self, current_transaction_time): + """ + 检查所有承租方对应的银行账号在property.bank.statements中是否有未对账流水 + :param current_transaction_time: 当前交易时间(带时区处理后) + """ + if not self.lessee_ids: + return + bank_accounts = self.env['property.bank.line'].search([ + ('tenant_id', 'in', self.lessee_ids.ids) + ]).mapped('bank') + bank_accounts = [acc for acc in bank_accounts if acc] # 过滤空值 + if not bank_accounts: + return + unreconciled = {} + for account in bank_accounts: + # 查询条件:同账号 + 交易时间早于当前 + 未对账 + statements = self.env['property.bank.statements'].search([ + ('name', '=', account), + ('start_time', '<', current_transaction_time), + ('bank_state', '=', 'not_reconciled'), + ('id', '!=', self.id), + ]) + if statements: + unreconciled[account] = len(statements) + + if unreconciled: + raise UserError("存在未对账的历史流水,请优先处理:") + def button_reconciliation(self): for record in self: all_vals, total_rent_month = self._get_reconciliation_vals(record) diff --git a/yuthon_property_approval/wizard/property_reconciliation_wizard.py b/yuthon_property_approval/wizard/property_reconciliation_wizard.py index 3d41c2256..e6fa71892 100644 --- a/yuthon_property_approval/wizard/property_reconciliation_wizard.py +++ b/yuthon_property_approval/wizard/property_reconciliation_wizard.py @@ -22,7 +22,7 @@ class PropertyReconciliationWizard(models.Model): initial_total = fields.Float(string='初始金额', default=0.0) rent = fields.Float(string='未收总租金', compute="_compute_rent_total") penalty = fields.Float(string='未收总违约金', compute="_compute_penalty_total") - remake = fields.Text(string='摘要') + remake = fields.Text(related='bank_id.remake', string='摘要') reconciliation_line_ids = fields.One2many('property.reconciliation.line', 'reconciliation_id', string='对账明细') @api.onchange('reconciliation_line_ids', 'actual_total') @@ -31,12 +31,11 @@ class PropertyReconciliationWizard(models.Model): rec.amount_reconciled = rec.actual_total - rec.amount_been_reconciled - sum(line.amount for line in rec.reconciliation_line_ids) for line in rec.reconciliation_line_ids: if line.amount: - if line.rent_month == line.amount and line.collection_type == 'rent' and (line.due_date.year != rec.actual_date.year or line.due_date.month != rec.actual_date.month): - line.remake = str(rec.actual_date) + '补' + str(line.due_date) - else: - line.remake = '' - else: - line.remake = '' + if line.due_date.year != rec.actual_date.year and line.due_date.month != rec.actual_date.month and line.collection_type == 'rent': + if line.rent_month == line.amount: + line.remake = str(rec.actual_date) + '补' + str(line.due_date) + '欠0' + elif line.rent > line.amount: + line.remake = str(rec.actual_date) + '补' + str(line.due_date) + '欠' + str(line.rent - line.amount) @api.depends('reconciliation_line_ids') def _compute_receivable_total(self):