From 86eed6c1ed7e3d86d38f7e398ae6501ef50c43f3 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Thu, 24 Nov 2022 12:55:29 +0100 Subject: [PATCH] [MIG] account_move_name_sequence: Migration to 16.0 --- account_move_name_sequence/__manifest__.py | 2 +- .../models/account_journal.py | 23 ++++---- .../readme/CONTRIBUTORS.rst | 15 ++++- .../tests/test_account_move_name_seq.py | 56 ++++++++++++++++++- .../views/account_move.xml | 16 +++--- 5 files changed, 87 insertions(+), 25 deletions(-) diff --git a/account_move_name_sequence/__manifest__.py b/account_move_name_sequence/__manifest__.py index fec5f01f..d35084b3 100644 --- a/account_move_name_sequence/__manifest__.py +++ b/account_move_name_sequence/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Account Move Number Sequence", - "version": "15.0.1.1.0", + "version": "16.0.1.0.0", "category": "Accounting", "license": "AGPL-3", "summary": "Generate journal entry number from sequence", diff --git a/account_move_name_sequence/models/account_journal.py b/account_move_name_sequence/models/account_journal.py index 9038ec2a..3cfd1531 100644 --- a/account_move_name_sequence/models/account_journal.py +++ b/account_move_name_sequence/models/account_journal.py @@ -67,17 +67,18 @@ class AccountJournal(models.Model): ) raise ValidationError(msg) - @api.model - def create(self, vals): - if not vals.get("sequence_id"): - vals["sequence_id"] = self._create_sequence(vals).id - if ( - vals.get("type") in ("sale", "purchase") - and vals.get("refund_sequence") - and not vals.get("refund_sequence_id") - ): - vals["refund_sequence_id"] = self._create_sequence(vals, refund=True).id - return super().create(vals) + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if not vals.get("sequence_id"): + vals["sequence_id"] = self._create_sequence(vals).id + if ( + vals.get("type") in ("sale", "purchase") + and vals.get("refund_sequence") + and not vals.get("refund_sequence_id") + ): + vals["refund_sequence_id"] = self._create_sequence(vals, refund=True).id + return super().create(vals_list) @api.model def _prepare_sequence(self, vals, refund=False): diff --git a/account_move_name_sequence/readme/CONTRIBUTORS.rst b/account_move_name_sequence/readme/CONTRIBUTORS.rst index 3e871242..39d07df2 100644 --- a/account_move_name_sequence/readme/CONTRIBUTORS.rst +++ b/account_move_name_sequence/readme/CONTRIBUTORS.rst @@ -1,3 +1,12 @@ -* Alexis de Lattre -* Moisés López -* Francisco Luna +* `Akretion `_: + + * Alexis de Lattre + +* `Vauxoo `_: + + * Moisés López + * Francisco Luna + +* `Factor Libre `_: + + * Rodrigo Bonilla Martinez diff --git a/account_move_name_sequence/tests/test_account_move_name_seq.py b/account_move_name_sequence/tests/test_account_move_name_seq.py index 207ca613..4538ccd5 100644 --- a/account_move_name_sequence/tests/test_account_move_name_seq.py +++ b/account_move_name_sequence/tests/test_account_move_name_seq.py @@ -9,7 +9,7 @@ from datetime import datetime from freezegun import freeze_time from odoo import fields -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError from odoo.tests import tagged from odoo.tests.common import TransactionCase @@ -168,7 +168,7 @@ class TestAccountMoveNameSequence(TransactionCase): in_refund_invoice.action_post() self.assertEqual(in_refund_invoice.name, move_name) - def test_remove_invoice_error(self): + def test_remove_invoice_error_secuence_no_grap(self): invoice = self.env["account.move"].create( { "date": self.date, @@ -189,3 +189,55 @@ class TestAccountMoveNameSequence(TransactionCase): error_msg = "You cannot delete this entry, as it has already consumed a" with self.assertRaisesRegex(UserError, error_msg): invoice.unlink() + + def test_remove_invoice_error_secuence_standard(self): + implementation = {"implementation": "standard"} + self.purchase_journal.sequence_id.write(implementation) + self.purchase_journal.refund_sequence_id.write(implementation) + in_refund_invoice = self.env["account.move"].create( + { + "journal_id": self.purchase_journal.id, + "invoice_date": self.date, + "partner_id": self.env.ref("base.res_partner_3").id, + "move_type": "in_refund", + "invoice_line_ids": [ + ( + 0, + 0, + { + "account_id": self.account1.id, + "price_unit": 42.0, + "quantity": 12, + }, + ) + ], + } + ) + in_refund_invoice._compute_split_sequence() + self.assertEqual(in_refund_invoice.name, "/") + in_refund_invoice.action_post() + error_msg = "You cannot delete an item linked to a posted entry." + with self.assertRaisesRegex(UserError, error_msg): + in_refund_invoice.unlink() + in_refund_invoice.button_draft() + in_refund_invoice.button_cancel() + self.assertTrue(in_refund_invoice.unlink()) + + def test_journal_check_journal_sequence(self): + new_journal = self.purchase_journal.copy() + # same sequence_id and refund_sequence_id + with self.assertRaises(ValidationError): + new_journal.write({"refund_sequence_id": new_journal.sequence_id}) + + # company_id in sequence_id or refund_sequence_id to False + new_sequence_id = new_journal.sequence_id.copy({"company_id": False}) + new_refund_sequence_id = new_journal.refund_sequence_id.copy( + {"company_id": False} + ) + with self.assertRaises(ValidationError): + new_journal.write({"sequence_id": new_sequence_id.id}) + with self.assertRaises(ValidationError): + new_journal.write({"refund_sequence_id": new_refund_sequence_id.id}) + + def test_constrains_date_sequence_true(self): + self.assertTrue(self.env["account.move"]._constrains_date_sequence()) diff --git a/account_move_name_sequence/views/account_move.xml b/account_move_name_sequence/views/account_move.xml index 2536e906..c537b17a 100644 --- a/account_move_name_sequence/views/account_move.xml +++ b/account_move_name_sequence/views/account_move.xml @@ -10,20 +10,20 @@ account.move - - {'invisible': [('name', '=', '/')]} + + 1 - {'readonly': 1} + {'invisible': [('name', '=', '/')]} + 1 - - {'invisible': 1} + + {'invisible': ['|', ('state', '!=', 'draft'), ('name', '!=', '/')]}