Skip to content

Commit

Permalink
[FIX] account_move_name_sequence: call flush before _fetch_duplicate_…
Browse files Browse the repository at this point in the history
…supplier_reference method

same issue OCA#1501
this fix not working for v16 OCA#1514
  • Loading branch information
RodrigoBM authored and moitabenfdz committed Nov 13, 2023
1 parent 6eeafb3 commit d53b869
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 12 deletions.
25 changes: 17 additions & 8 deletions account_move_name_sequence/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -108,7 +108,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/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 <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_name_sequence%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_name_sequence%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -124,9 +124,18 @@ Authors
Contributors
~~~~~~~~~~~~

* Alexis de Lattre <[email protected]>
* Moisés López <[email protected]>
* Francisco Luna <[email protected]>
* `Akretion <https://www.akretion.com>`_:

* Alexis de Lattre <[email protected]>

* `Vauxoo <https://www.vauxoo.com>`_:

* Moisés López <[email protected]>
* Francisco Luna <[email protected]>

* `Factor Libre <https://www.factorlibre.com>`_:

* Rodrigo Bonilla Martinez <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down Expand Up @@ -155,6 +164,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-alexis-via| |maintainer-moylop260| |maintainer-frahikLV|

This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/15.0/account_move_name_sequence>`_ project on GitHub.
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/16.0/account_move_name_sequence>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ""
Expand All @@ -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
Expand All @@ -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 ""
Expand All @@ -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 ""
Expand Down
6 changes: 6 additions & 0 deletions account_move_name_sequence/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ def _is_end_of_seq_chain(self):
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)
16 changes: 13 additions & 3 deletions account_move_name_sequence/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Account Move Number Sequence</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/15.0/account_move_name_sequence"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-account_move_name_sequence"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/92/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/16.0/account_move_name_sequence"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_move_name_sequence"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/92/16.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>In Odoo version 13.0 and previous versions, the number of journal entries was generated from a sequence configured on the journal.</p>
<p>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:</p>
<ul class="simple">
Expand Down Expand Up @@ -448,7 +448,7 @@ <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_name_sequence%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_name_sequence%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -463,10 +463,20 @@ <h2><a class="toc-backref" href="#id5">Authors</a></h2>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.akretion.com">Akretion</a>:<ul>
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis.delattre&#64;akretion.com">alexis.delattre&#64;akretion.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://www.vauxoo.com">Vauxoo</a>:<ul>
<li>Moisés López &lt;<a class="reference external" href="mailto:moylop260&#64;vauxoo.com">moylop260&#64;vauxoo.com</a>&gt;</li>
<li>Francisco Luna &lt;<a class="reference external" href="mailto:fluna&#64;vauxoo.com">fluna&#64;vauxoo.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://www.factorlibre.com">Factor Libre</a>:<ul>
<li>Rodrigo Bonilla Martinez &lt;<a class="reference external" href="mailto:rodrigo.bonilla&#64;factorlibre.com">rodrigo.bonilla&#64;factorlibre.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
Expand All @@ -477,7 +487,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a> <a class="reference external" href="https://github.com/moylop260"><img alt="moylop260" src="https://github.com/moylop260.png?size=40px" /></a> <a class="reference external" href="https://github.com/frahikLV"><img alt="frahikLV" src="https://github.com/frahikLV.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/15.0/account_move_name_sequence">OCA/account-financial-tools</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/16.0/account_move_name_sequence">OCA/account-financial-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
96 changes: 96 additions & 0 deletions account_move_name_sequence/tests/test_account_move_name_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,102 @@ def test_prefix_move_name_use_move_date(self):
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(
{
Expand Down

0 comments on commit d53b869

Please sign in to comment.