Skip to content

Commit

Permalink
[MIG] account_move_name_sequence: Migration to 18.0
Browse files Browse the repository at this point in the history
- Rename the method `_fetch_duplicate_supplier_reference` to
  `_fetch_duplicate_reference` to include both sale and purchase
  documents.
- Refactor tests to use `SetUpClass`, update the creation of payments
  with a related journal entry, and include the deletion of payments
  when deleting the moves.
- Patch the `_validate_fields` and `_hash_moves` methods in tests to
  simulate the same behavior as if the journal entries are unlocked.
  This is done because, in the pipeline, the
  `account_journal_restrict_mode` module is installed, and it locks
  posted entries, preventing them from being set to draft or deleted
  afterward.
- Add additional tests for the sequence prefix to increase coverage.

Co-authored-by: Bert Van Groenendael <[email protected]>
Co-authored-by: oury.balde <[email protected]>
  • Loading branch information
3 people committed Jan 22, 2025
1 parent 6a4ad6a commit 5459aa7
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 114 deletions.
48 changes: 26 additions & 22 deletions account_move_name_sequence/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,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/17.0/account_move_name_sequence
:target: https://github.com/OCA/account-financial-tools/tree/18.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-17-0/account-financial-tools-17-0-account_move_name_sequence
:target: https://translation.odoo-community.org/projects/account-financial-tools-18-0/account-financial-tools-18-0-account_move_name_sequence
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -37,16 +37,16 @@ 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:

- the available options for the sequence are limited,
- it is not possible to configure the sequence in advance before the
deployment in production,
- as it is error-prone, they added a *Resequence* wizard to re-generate
the journal entry numbers, which can be considered as illegal in many
countries,
- the `piece of
code <https://github.com/odoo/odoo/blob/14.0/addons/account/models/sequence_mixin.py>`__
that handles this is not easy to understand and quite difficult to
debug.
- the available options for the sequence are limited,
- it is not possible to configure the sequence in advance before the
deployment in production,
- as it is error-prone, they added a *Resequence* wizard to re-generate
the journal entry numbers, which can be considered as illegal in many
countries,
- the `piece of
code <https://github.com/odoo/odoo/blob/14.0/addons/account/models/sequence_mixin.py>`__
that handles this is not easy to understand and quite difficult to
debug.

Using this module, you can configure what kind of documents the gap
sequence may be relaxed And even if you must use no-gap in your company
Expand Down Expand Up @@ -98,7 +98,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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_name_sequence%0Aversion:%2017.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:%2018.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 @@ -114,18 +114,22 @@ Authors
Contributors
------------

- `Akretion <https://www.akretion.com>`__:
- `Akretion <https://www.akretion.com>`__:

- Alexis de Lattre <[email protected]>
- Alexis de Lattre <[email protected]>

- `Vauxoo <https://www.vauxoo.com>`__:
- `Vauxoo <https://www.vauxoo.com>`__:

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

- `Factor Libre <https://www.factorlibre.com>`__:
- `Factor Libre <https://www.factorlibre.com>`__:

- Rodrigo Bonilla Martinez <[email protected]>
- Rodrigo Bonilla Martinez <[email protected]>

- `Dynapps <https://www.dynapps.eu>`__:

- Bert Van Groenendael <[email protected]>

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

|maintainer-alexis-via| |maintainer-moylop260| |maintainer-luisg123v|

This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/17.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/18.0/account_move_name_sequence>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_move_name_sequence/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{
"name": "Account Move Number Sequence",
"version": "17.0.1.0.5",
"version": "18.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "Generate journal entry number from sequence",
Expand Down
27 changes: 17 additions & 10 deletions account_move_name_sequence/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import logging

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)
Expand All @@ -30,7 +30,8 @@ class AccountJournal(models.Model):
copy=False,
check_company=True,
domain="[('company_id', '=', company_id)]",
help="This sequence will be used to generate the journal entry number for refunds.",
help="This sequence will be used to generate "
"the journal entry number for refunds.",
)
# Redefine the default to True as <=v13.0
refund_sequence = fields.Boolean(default=True)
Expand All @@ -47,22 +48,22 @@ def _check_journal_sequence(self):
and journal.refund_sequence_id == journal.sequence_id
):
raise ValidationError(
_(
self.env._(
"On journal '%s', the same sequence is used as "
"Entry Sequence and Credit Note Entry Sequence.",
journal.display_name,
)
)
if journal.sequence_id and not journal.sequence_id.company_id:
msg = _(
msg = self.env._(
"The company is not set on sequence '%(sequence)s' configured on "
"journal '%(journal)s'.",
sequence=journal.sequence_id.display_name,
journal=journal.display_name,
)
raise ValidationError(msg)
if journal.refund_sequence_id and not journal.refund_sequence_id.company_id:
msg = _(
msg = self.env._(
"The company is not set on sequence '%(sequence)s' configured as "
"credit note sequence of journal '%(journal)s'.",
sequence=journal.refund_sequence_id.display_name,
Expand All @@ -89,7 +90,8 @@ def _prepare_sequence(self, vals, refund=False):
prefix = "{}{}/%(range_year)s/".format(refund and "R" or "", code)
seq_vals = {
"name": "{}{}".format(
vals.get("name", _("Sequence")), refund and " " + _("Refund") or ""
vals.get("name", self.env._("Sequence")),
refund and " " + self.env._("Refund") or "",
),
"company_id": vals.get("company_id") or self.env.company.id,
"implementation": "no_gap",
Expand Down Expand Up @@ -129,7 +131,7 @@ def _prepare_sequence_current_moves(self, refund=False):
"Using default values.".format(self.id, refund and "refund" or "")
)
if not last_move:
_logger.warning("%s %s", msg_err, "No moves found")
_logger.debug("%s %s", msg_err, "No moves found")
return {}
try:
with self.env.cr.savepoint():
Expand Down Expand Up @@ -188,10 +190,15 @@ def _prepare_sequence_current_moves(self, refund=False):
if prefix3
else "''"
)
select_max_number = f"MAX(split_part(name, '{prefixes[-1]}', {prefixes.count(prefixes[-1]) + 1})::INTEGER) AS max_number"
select_max_number = (
f"MAX(split_part(name, '{prefixes[-1]}', "
f"{prefixes.count(prefixes[-1]) + 1}):"
f":INTEGER) AS max_number"
)
query = (
f"SELECT {select_year}, {select_month}, {select_max_number} FROM account_move "
"WHERE name LIKE %s AND journal_id=%s GROUP BY 1,2"
f"SELECT {select_year}, {select_month}, "
f"{select_max_number} FROM account_move "
f"WHERE name LIKE %s AND journal_id=%s GROUP BY 1,2"
)

# It is not using user input
Expand Down
9 changes: 6 additions & 3 deletions account_move_name_sequence/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ def _is_end_of_seq_chain(self):
return False
return super(AccountMove, invoices_other_sequences)._is_end_of_seq_chain()

Check warning on line 70 in account_move_name_sequence/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_name_sequence/models/account_move.py#L69-L70

Added lines #L69 - L70 were not covered by tests

def _fetch_duplicate_supplier_reference(self, only_posted=False):
moves = self.filtered(lambda m: m.is_purchase_document() and m.ref)
def _fetch_duplicate_reference(self, matching_states=("draft", "posted")):
moves = self.filtered(
lambda m: m.is_sale_document() or 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)
return super()._fetch_duplicate_reference(matching_states=matching_states)

def _get_last_sequence(self, relaxed=False, with_prefix=None):
return super()._get_last_sequence(relaxed, None)
Expand All @@ -88,6 +90,7 @@ def _post(self, soft=True):
self.flush_recordset()
return super()._post(soft=soft)

@api.depends()
def _compute_name(self):
"""Overwrite account module method in order to
avoid side effect if legacy code call it directly
Expand Down
2 changes: 2 additions & 0 deletions account_move_name_sequence/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
- Francisco Luna \<<[email protected]>\>
- [Factor Libre](https://www.factorlibre.com):
- Rodrigo Bonilla Martinez \<<[email protected]>\>
- [Dynapps](https://www.dynapps.eu):
- Bert Van Groenendael \<<[email protected]>\>
21 changes: 14 additions & 7 deletions account_move_name_sequence/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">Account Move Number Sequence</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:03b876b8607b5c34b0f49870637439187af2b3913e3af50d384838d28ef870ee
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/account-financial-tools/tree/17.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 image-reference" href="https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-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 image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/account-financial-tools/tree/18.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 image-reference" href="https://translation.odoo-community.org/projects/account-financial-tools-18-0/account-financial-tools-18-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 image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-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
Expand Down Expand Up @@ -438,7 +439,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">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 to smash 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:%2017.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:%2018.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 Down Expand Up @@ -466,18 +467,24 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<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>
<li><a class="reference external" href="https://www.dynapps.eu">Dynapps</a>:<ul>
<li>Bert Van Groenendael &lt;<a class="reference external" href="mailto:bert.vangroenendael&#64;dynapps.eu">bert.vangroenendael&#64;dynapps.eu</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
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 image-reference" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/moylop260"><img alt="moylop260" src="https://github.com/moylop260.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/luisg123v"><img alt="luisg123v" src="https://github.com/luisg123v.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/17.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/18.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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class TestAccountIncomingSupplierInvoice(AccountTestInvoicingCommon):
"""Testing creating account move fetching mail.alias"""

@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
def setUpClass(cls):
super().setUpClass()

cls.env["ir.config_parameter"].sudo().set_param(
"mail.catchall.domain", "test-company.odoo.com"
Expand Down Expand Up @@ -59,14 +59,25 @@ def test_supplier_invoice_mailed_from_supplier(self):
message_parsed = {
"message_id": "message-id-dead-beef",
"subject": "Incoming bill",
"from": f"{self.supplier_partner.name} <{self.supplier_partner.email}>",
"to": f"{self.journal.alias_id.alias_name}@{self.journal.alias_id.alias_domain}",
"from": f"{self.supplier_partner.name} " f"<{self.supplier_partner.email}>",
"to": f"{self.journal.alias_id.alias_name}@"
f"{self.journal.alias_id.alias_domain}",
"body": "You know, that thing that you bought.",
"attachments": [b"Hello, invoice"],
}

invoice = self.env["account.move"].message_new(
message_parsed, {"move_type": "in_invoice", "journal_id": self.journal.id}
invoice = (
self.env["account.move"]
.with_context(
tracking_disable=False,
mail_create_nolog=False,
mail_create_nosubscribe=False,
mail_notrack=False,
)
.message_new(
message_parsed,
{"move_type": "in_invoice", "journal_id": self.journal.id},
)
)

message_ids = invoice.message_ids
Expand Down
Loading

0 comments on commit 5459aa7

Please sign in to comment.