diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index f5bdae624..610502d82 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -57,6 +57,32 @@ class PropertyBankStatements(models.Model): ]) if bank_lines: tenant_id = bank_lines[0].tenant_id.id + rec.bank_state = 'not_reconciled' + rec.registered = 0 + rec.no_amount = rec.original_amount + rec.yes_amount = 0 + penalty_records = self.env['property.accounts.receivable'].search([('bank_id', '=', self.id)]) + if not penalty_records: + penalty_records = self.env['property.accounts.receivable'].search([ + ('due_date', '=', start_date), + ('lessee_id', '=', tenant_id), + ('contract_id', 'in', rec.contract_ids.ids), + ('property_id', 'in', rec.property_ids.ids), + ('management_type_id', '=', penalty_type.id) + ]) + to_restore = penalty_records.filtered(lambda r: r.is_write) + if to_restore: + to_restore.write({'is_write': False, + 'due_date_end': None, + 'delivered1': None, + 'is_reconciliation': False, + 'payout_date': None, + }) + return + to_delete = penalty_records.filtered(lambda r: not r.is_write) + if to_delete: + to_delete.unlink() + accounts = self.env['property.accounts.receivable'].search([ ('payout_date', '=', start_date), ('lessee_id', '=', tenant_id), @@ -64,41 +90,15 @@ class PropertyBankStatements(models.Model): ('property_id', 'in', rec.property_ids.ids), ('management_type_id', '!=', penalty_type.id), ]) - rec.bank_state = 'not_reconciled' - rec.registered = 0 - rec.no_amount = rec.original_amount - rec.yes_amount = 0 if accounts: for account in accounts: account.write({'is_reconciliation': False, 'payout_date': False, 'delivered1': 0, - 'due_date_end' :None, - 'reconciliation_time': False, - 'remark':None, + 'due_date_end': None, + 'reconciliation_time': False, + 'remark': None, }) - penalty_records = self.env['property.accounts.receivable'].search([('bank_id', '=', self.id)]) - if not penalty_records: - penalty_records = self.env['property.accounts.receivable'].search([ - ('due_date', '=', start_date), - ('lessee_id', '=', tenant_id), - ('contract_id', 'in', rec.contract_ids.ids), - ('property_id', 'in', rec.property_ids.ids), - ('management_type_id', '=', penalty_type.id) - ]) - to_restore = penalty_records.filtered(lambda r: r.is_write) - if to_restore: - to_restore.write({'is_write': False, - 'due_date_end': None, - 'delivered1': None, - 'is_reconciliation': False, - 'payout_date': None, - }) - return - - to_delete = penalty_records.filtered(lambda r: not r.is_write) - if to_delete: - to_delete.unlink() def binding_information(self): return {