From d53b8698ec48b3e49e3303891c727f51c86e389a Mon Sep 17 00:00:00 2001
From: Rodrigo
Date: Fri, 2 Dec 2022 12:57:26 +0100
Subject: [PATCH] [FIX] account_move_name_sequence: call flush before
_fetch_duplicate_supplier_reference method same issue
https://github.com/OCA/account-financial-tools/issues/1501 this fix not
working for v16 https://github.com/OCA/account-financial-tools/pull/1514
---
account_move_name_sequence/README.rst | 25 +++--
.../i18n/account_move_name_sequence.pot | 7 +-
.../models/account_move.py | 6 ++
.../static/description/index.html | 16 +++-
.../tests/test_account_move_name_seq.py | 96 +++++++++++++++++++
5 files changed, 138 insertions(+), 12 deletions(-)
diff --git a/account_move_name_sequence/README.rst b/account_move_name_sequence/README.rst
index 0d9fe0a78..d77bab031 100644
--- a/account_move_name_sequence/README.rst
+++ b/account_move_name_sequence/README.rst
@@ -14,13 +14,13 @@ Account Move Number Sequence
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github
- :target: https://github.com/OCA/account-financial-tools/tree/15.0/account_move_name_sequence
+ :target: https://github.com/OCA/account-financial-tools/tree/16.0/account_move_name_sequence
:alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-account_move_name_sequence
+ :target: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_move_name_sequence
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
- :target: https://runbot.odoo-community.org/runbot/92/15.0
+ :target: https://runbot.odoo-community.org/runbot/92/16.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -108,7 +108,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -124,9 +124,18 @@ Authors
Contributors
~~~~~~~~~~~~
-* 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
Maintainers
~~~~~~~~~~~
@@ -155,6 +164,6 @@ Current `maintainers `__:
|maintainer-alexis-via| |maintainer-moylop260| |maintainer-frahikLV|
-This module is part of the `OCA/account-financial-tools `_ project on GitHub.
+This module is part of the `OCA/account-financial-tools `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/account_move_name_sequence/i18n/account_move_name_sequence.pot b/account_move_name_sequence/i18n/account_move_name_sequence.pot
index b9aa2fba1..4b400c5d1 100644
--- a/account_move_name_sequence/i18n/account_move_name_sequence.pot
+++ b/account_move_name_sequence/i18n/account_move_name_sequence.pot
@@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: Odoo Server 15.0\n"
+"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -67,6 +67,7 @@ msgid "Number"
msgstr ""
#. module: account_move_name_sequence
+#. odoo-python
#: code:addons/account_move_name_sequence/models/account_journal.py:0
#, python-format
msgid ""
@@ -75,12 +76,14 @@ msgid ""
msgstr ""
#. module: account_move_name_sequence
+#. odoo-python
#: code:addons/account_move_name_sequence/models/account_journal.py:0
#, python-format
msgid "Refund"
msgstr ""
#. module: account_move_name_sequence
+#. odoo-python
#: code:addons/account_move_name_sequence/models/account_journal.py:0
#: model:ir.model,name:account_move_name_sequence.model_ir_sequence
#, python-format
@@ -102,6 +105,7 @@ msgid "Sequence Prefix"
msgstr ""
#. module: account_move_name_sequence
+#. odoo-python
#: code:addons/account_move_name_sequence/models/account_journal.py:0
#, python-format
msgid ""
@@ -110,6 +114,7 @@ msgid ""
msgstr ""
#. module: account_move_name_sequence
+#. odoo-python
#: code:addons/account_move_name_sequence/models/account_journal.py:0
#, python-format
msgid ""
diff --git a/account_move_name_sequence/models/account_move.py b/account_move_name_sequence/models/account_move.py
index 8813263f7..8b43a629f 100644
--- a/account_move_name_sequence/models/account_move.py
+++ b/account_move_name_sequence/models/account_move.py
@@ -64,3 +64,9 @@ class AccountMove(models.Model):
if not invoices_other_sequences and invoices_no_gap_sequences:
return False
return super(AccountMove, invoices_other_sequences)._is_end_of_seq_chain()
+
+ def _fetch_duplicate_supplier_reference(self, only_posted=False):
+ moves = self.filtered(lambda m: m.is_purchase_document() and m.ref)
+ if moves:
+ self.flush_model(["name", "journal_id", "move_type", "state"])
+ return super()._fetch_duplicate_supplier_reference(only_posted=only_posted)
diff --git a/account_move_name_sequence/static/description/index.html b/account_move_name_sequence/static/description/index.html
index e02281983..84b1cf9e6 100644
--- a/account_move_name_sequence/static/description/index.html
+++ b/account_move_name_sequence/static/description/index.html
@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

+

In Odoo version 13.0 and previous versions, the number of journal entries was generated from a sequence configured on the journal.
In Odoo version 14.0, the number of journal entries can be manually set by the user. Then, the number attributed for the next journal entries in the same journal is computed by a complex piece of code that guesses the format of the journal entry number from the number of the journal entry which was manually entered by the user. It has several drawbacks:
@@ -448,7 +448,7 @@ And even if you must use no-gap in your company or country it will reduce the co
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
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 4538ccd50..4457da0c0 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
@@ -138,6 +138,102 @@ class TestAccountMoveNameSequence(TransactionCase):
move.action_post()
self.assertEqual(move.name, "TEST-2022-07-0001")
+ def test_in_invoice_and_refund(self):
+ in_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_invoice",
+ "invoice_line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account1.id,
+ "price_unit": 42.0,
+ "quantity": 12,
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account1.id,
+ "price_unit": 48.0,
+ "quantity": 10,
+ },
+ ),
+ ],
+ }
+ )
+ self.assertEqual(in_invoice.name, "/")
+ in_invoice.action_post()
+
+ move_reversal = (
+ self.env["account.move.reversal"]
+ .with_context(active_model="account.move", active_ids=in_invoice.ids)
+ .create(
+ {
+ "journal_id": in_invoice.journal_id.id,
+ "reason": "no reason",
+ "refund_method": "cancel",
+ }
+ )
+ )
+ reversal = move_reversal.reverse_moves()
+ reversed_move = self.env["account.move"].browse(reversal["res_id"])
+ self.assertTrue(reversed_move)
+ self.assertEqual(reversed_move.state, "posted")
+
+ in_invoice = in_invoice.copy(
+ {
+ "invoice_date": self.date,
+ }
+ )
+ in_invoice.action_post()
+
+ move_reversal = (
+ self.env["account.move.reversal"]
+ .with_context(active_model="account.move", active_ids=in_invoice.ids)
+ .create(
+ {
+ "journal_id": in_invoice.journal_id.id,
+ "reason": "no reason",
+ "refund_method": "modify",
+ }
+ )
+ )
+ reversal = move_reversal.reverse_moves()
+ draft_invoice = self.env["account.move"].browse(reversal["res_id"])
+ self.assertTrue(draft_invoice)
+ self.assertEqual(draft_invoice.state, "draft")
+ self.assertEqual(draft_invoice.move_type, "in_invoice")
+
+ in_invoice = in_invoice.copy(
+ {
+ "invoice_date": self.date,
+ }
+ )
+ in_invoice.action_post()
+
+ move_reversal = (
+ self.env["account.move.reversal"]
+ .with_context(active_model="account.move", active_ids=in_invoice.ids)
+ .create(
+ {
+ "journal_id": in_invoice.journal_id.id,
+ "reason": "no reason",
+ "refund_method": "refund",
+ }
+ )
+ )
+ reversal = move_reversal.reverse_moves()
+ draft_reversed_move = self.env["account.move"].browse(reversal["res_id"])
+ self.assertTrue(draft_reversed_move)
+ self.assertEqual(draft_reversed_move.state, "draft")
+ self.assertEqual(draft_reversed_move.move_type, "in_refund")
+
def test_in_refund(self):
in_refund_invoice = self.env["account.move"].create(
{