diff --git a/account_move_reconcile_forbid_cancel/__manifest__.py b/account_move_reconcile_forbid_cancel/__manifest__.py index 4f42f6ea..723e7dd7 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": "13.0.1.0.0", + "version": "13.0.1.0.1", "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 5c84a133..a05a0677 100644 --- a/account_move_reconcile_forbid_cancel/models/account_move.py +++ b/account_move_reconcile_forbid_cancel/models/account_move.py @@ -10,7 +10,7 @@ class AccountMove(models.Model): def _get_receivable_payable_lines(self): return self.line_ids.filtered( - lambda l: l.account_internal_type in ["receivable", "acc_type_pay"], + lambda l: l.account_internal_type in ["receivable", "payable"], ) def button_draft(self): 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 6edabd3e..2818bca4 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 @@ -9,9 +9,15 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase): @classmethod def setUpClass(cls): super().setUpClass() - journal_sale = cls.env["account.journal"].create( + purchase_journal = cls.env["account.journal"].create( + {"name": "Purchase journal", "code": "PJ", "type": "purchase"} + ) + sale_journal = cls.env["account.journal"].create( {"name": "Sale journal", "code": "SJ", "type": "sale"} ) + cls.env["account.journal"].create( + {"name": "Bank Journal", "code": "BANK", "type": "bank"} + ) receivable_account_type = cls.env["account.account.type"].create( { "name": "Receivable account type", @@ -19,6 +25,13 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase): "internal_group": "asset", } ) + payable_account_type = cls.env["account.account.type"].create( + { + "name": "Payable account type", + "type": "payable", + "internal_group": "liability", + } + ) income_account_type = cls.env["account.account.type"].create( { "name": "Income account type", @@ -26,6 +39,13 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase): "internal_group": "income", } ) + expense_account_type = cls.env["account.account.type"].create( + { + "name": "Expense account type", + "type": "other", + "internal_group": "expense", + } + ) receivable_account = cls.env["account.account"].create( { "name": "Receivable Account", @@ -34,6 +54,14 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase): "reconcile": True, } ) + payable_account = cls.env["account.account"].create( + { + "name": "Payable Account", + "code": "PAY", + "user_type_id": payable_account_type.id, + "reconcile": True, + } + ) income_account = cls.env["account.account"].create( { "name": "Income Account", @@ -42,42 +70,83 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase): "reconcile": False, } ) + expense_account = cls.env["account.account"].create( + { + "name": "Expense Account", + "code": "EXP", + "user_type_id": expense_account_type.id, + "reconcile": False, + } + ) partner = cls.env["res.partner"].create( { "name": "Partner test", "property_account_receivable_id": receivable_account.id, + "property_account_payable_id": payable_account.id, } ) product = cls.env["product.product"].create( - {"name": "Product Test", "property_account_income_id": income_account.id} + { + "name": "Product Test", + "property_account_income_id": income_account.id, + "property_account_expense_id": expense_account.id, + } ) - # Create invoice + # Create a purchase invoice move_form = Form( - cls.env["account.move"].with_context(default_type="out_invoice") + cls.env["account.move"].with_context(default_type="in_invoice") ) - move_form.journal_id = journal_sale + move_form.journal_id = purchase_journal move_form.partner_id = partner with move_form.invoice_line_ids.new() as line_form: line_form.product_id = product line_form.price_unit = 100.0 - cls.invoice = move_form.save() - cls.invoice.action_post() + cls.purchase_invoice = move_form.save() + cls.purchase_invoice.action_post() # Create payment from invoice - cls.env["account.journal"].create( - {"name": "Bank Journal", "code": "BANK", "type": "bank"} - ) - payment_register = Form( + payment_register_form = Form( cls.env["account.payment"].with_context( - active_model="account.move", active_ids=cls.invoice.ids, + active_model="account.move", active_ids=cls.purchase_invoice.ids, ) ) - cls.payment = payment_register.save() - cls.payment.post() + payment = payment_register_form.save() + payment.post() + # Create a sale invoice + move_form = Form( + cls.env["account.move"].with_context(default_type="out_invoice") + ) + move_form.journal_id = sale_journal + move_form.partner_id = partner + with move_form.invoice_line_ids.new() as line_form: + line_form.product_id = product + line_form.price_unit = 100.0 + cls.sale_invoice = move_form.save() + cls.sale_invoice.action_post() + # Create payment from invoice + payment_register_form = Form( + cls.env["account.payment"].with_context( + active_model="account.move", active_ids=cls.sale_invoice.ids, + ) + ) + payment = payment_register_form.save() + payment.post() def test_reset_invoice_to_draft(self): with self.assertRaises(ValidationError): - self.invoice.with_context(test_reconcile_forbid_cancel=True).button_draft() + self.purchase_invoice.with_context( + test_reconcile_forbid_cancel=True + ).button_draft() + with self.assertRaises(ValidationError): + self.sale_invoice.with_context( + test_reconcile_forbid_cancel=True + ).button_draft() def test_cancel_invoice(self): with self.assertRaises(ValidationError): - self.invoice.with_context(test_reconcile_forbid_cancel=True).button_cancel() + self.purchase_invoice.with_context( + test_reconcile_forbid_cancel=True + ).button_cancel() + with self.assertRaises(ValidationError): + self.sale_invoice.with_context( + test_reconcile_forbid_cancel=True + ).button_cancel()