From fb7e9d2ac15e0f7a258d9a58818a35fd43d20861 Mon Sep 17 00:00:00 2001 From: Alejandro Ji Cheung Date: Wed, 19 Jul 2023 10:54:38 +0200 Subject: [PATCH] [MIG] account_move_reconcile_forbid_cancel: Migration to 16.0 --- account_move_reconcile_forbid_cancel/__manifest__.py | 2 +- .../models/account_move.py | 11 ++--------- .../test_account_move_reconcile_forbid_cancel.py | 10 ++++------ 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/account_move_reconcile_forbid_cancel/__manifest__.py b/account_move_reconcile_forbid_cancel/__manifest__.py index ee7b11ea..65553875 100644 --- a/account_move_reconcile_forbid_cancel/__manifest__.py +++ b/account_move_reconcile_forbid_cancel/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Account Move Reconcile Forbid Cancel", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Finance", "website": "https://github.com/OCA/account-reconcile", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/account_move_reconcile_forbid_cancel/models/account_move.py b/account_move_reconcile_forbid_cancel/models/account_move.py index ed3e8201..539ae708 100644 --- a/account_move_reconcile_forbid_cancel/models/account_move.py +++ b/account_move_reconcile_forbid_cancel/models/account_move.py @@ -8,18 +8,12 @@ from odoo.exceptions import ValidationError class AccountMove(models.Model): _inherit = "account.move" - def _get_receivable_payable_lines(self): - return self.line_ids.filtered( - lambda l: l.account_internal_type in ["receivable", "payable"], - ) - def button_draft(self): if not self.env.context.get("skip_reconcile_forbid_cancel") and ( not tools.config["test_enable"] or self.env.context.get("test_reconcile_forbid_cancel") ): - rec_pay_lines = self._get_receivable_payable_lines() - if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids: + if self._get_reconciled_amls(): raise ValidationError( _("You cannot reset to draft reconciled entries.") ) @@ -30,7 +24,6 @@ class AccountMove(models.Model): not tools.config["test_enable"] or self.env.context.get("test_reconcile_forbid_cancel") ): - rec_pay_lines = self._get_receivable_payable_lines() - if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids: + if self._get_reconciled_amls(): raise ValidationError(_("You cannot cancel reconciled entries.")) return super().button_cancel() diff --git a/account_move_reconcile_forbid_cancel/tests/test_account_move_reconcile_forbid_cancel.py b/account_move_reconcile_forbid_cancel/tests/test_account_move_reconcile_forbid_cancel.py index f5f7c92e..3ed4ca79 100644 --- a/account_move_reconcile_forbid_cancel/tests/test_account_move_reconcile_forbid_cancel.py +++ b/account_move_reconcile_forbid_cancel/tests/test_account_move_reconcile_forbid_cancel.py @@ -17,7 +17,7 @@ class TestAccountMoveReconcileForbidCancel(TransactionCase): { "name": "Receivable Account", "code": "REC", - "user_type_id": cls.env.ref("account.data_account_type_receivable").id, + "account_type": "asset_receivable", "reconcile": True, } ) @@ -25,7 +25,7 @@ class TestAccountMoveReconcileForbidCancel(TransactionCase): { "name": "Payable Account", "code": "PAY", - "user_type_id": cls.env.ref("account.data_account_type_payable").id, + "account_type": "liability_payable", "reconcile": True, } ) @@ -33,9 +33,7 @@ class TestAccountMoveReconcileForbidCancel(TransactionCase): { "name": "Income Account", "code": "INC", - "user_type_id": cls.env.ref( - "account.data_account_type_other_income" - ).id, + "account_type": "income", "reconcile": False, } ) @@ -43,7 +41,7 @@ class TestAccountMoveReconcileForbidCancel(TransactionCase): { "name": "Expense Account", "code": "EXP", - "user_type_id": cls.env.ref("account.data_account_type_expenses").id, + "account_type": "expense", "reconcile": False, } )