Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] account_move_name_sequence: Migration to 18.0 #2016

Open
wants to merge 61 commits into
base: 18.0
Choose a base branch
from

Conversation

CLaurelB
Copy link

Supersed: #1954

alexis-via and others added 30 commits January 20, 2025 18:39
This module restores the good old behavior where journal entry numbers
were generated from a sequence configured on the journal.
Add post-install script to create a sequence for all existing journals
Update README accordingly
…ange_day

More info about:
 - odoo/odoo#91019

TODO: Revert this commit after it is merged
After remove required=True for journal.sequence_id field it is possible to post an invoice with misconfigured journal with empty sequence

So, this constraint will raise an error for this kind of cases since that using '/' could raise the unique constraint for all other moves
The required flag was wrong for sequence_id and refund_sequence_id

So, it was not possible to store any change in journal for journal different to sale and purchase
…efix

In case you want name your invoice YYYY-MM-SEQ (ie: 2022-07-00001)
where:
 * YYYY: is the account move year
 * MM: is the account move month
 * SEQ: is a numerical sequence that is continue along the fiscal year
   assuming fiscal year is over two years (ie: from july to june next year)

Before this commit the sequence prefix use now() to be compute but the
range is selected with the account move date.

This commit make consistency computing prefix with the account
move date as well.

So account move manage the first janunary for the last day of
the previous year will properly use the account move date.

Co-authored-by: Alexis de Lattre <[email protected]>
…supplier_reference method

same issue OCA#1501
this fix not working for v16 OCA#1514
…e" module the "_get_last_sequence" method does not have to propagate the with_prefix parameter. The sequence_prefix parameter will not be completed and will give error as it is False in this line of code. https://github.com/OCA/OCB/blob/16.0/addons/account/models/sequence_mixin.py#L169
Currently translated at 100.0% (20 of 20 strings)

Translation: account-financial-tools-16.0/account-financial-tools-16.0-account_move_name_sequence
Translate-URL: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_move_name_sequence/fr/
Rename hooks file and use post_init_hook method to create journal sequences
after module installation.
…the name

The core compute function for the name is calling at the end the function self._inverse_name(),
which updates the payment_reference when required.
This code was currently missing, causing the payment_reference not being properly computed,
for example, when using QR-Bills.
OCA-git-bot and others added 11 commits January 20, 2025 18:39
…invoices

Add demo data with standard implementation sequences

In order to test locks issues without changing data (then reverting)
Split the context definition in sequence_id and refund_sequence_id
fields into multiple lines to improve readability.
Update name of view files to follow guidelines.
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: account-financial-tools-17.0/account-financial-tools-17.0-account_move_name_sequence
Translate-URL: https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-0-account_move_name_sequence/
Currently translated at 100.0% (22 of 22 strings)

Translation: account-financial-tools-17.0/account-financial-tools-17.0-account_move_name_sequence
Translate-URL: https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-0-account_move_name_sequence/it/
Currently translated at 100.0% (22 of 22 strings)

Translation: account-financial-tools-17.0/account-financial-tools-17.0-account_move_name_sequence
Translate-URL: https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-0-account_move_name_sequence/es/
@CLaurelB CLaurelB force-pushed the 18.0-mig-account_move_name_sequence-CLaurelB branch 5 times, most recently from 88a822c to 27ada85 Compare January 21, 2025 09:09
@CLaurelB
Copy link
Author

@luisg123v could you review, please?

@CLaurelB CLaurelB force-pushed the 18.0-mig-account_move_name_sequence-CLaurelB branch 3 times, most recently from 9215922 to c088e59 Compare January 21, 2025 19:57
Copy link

@thienvh332 thienvh332 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nitpicking 😉

and journal.refund_sequence_id == journal.sequence_id
):
raise ValidationError(
_(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_(
self.env._(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to some other positions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion applied.

@CLaurelB CLaurelB force-pushed the 18.0-mig-account_move_name_sequence-CLaurelB branch from c088e59 to 5459aa7 Compare January 22, 2025 04:19
@CLaurelB CLaurelB requested a review from thienvh332 January 22, 2025 04:22
@@ -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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this change? I think it would be more reasonable for us to WARNING?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change reverted.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, You can use assertLogs to intercept and check for warnings. It will help you pass the tests below 😉

Copy link
Author

@CLaurelB CLaurelB Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the issue was in the post_init_hook, I added a context validation to mute the warning when desired.

@CLaurelB CLaurelB force-pushed the 18.0-mig-account_move_name_sequence-CLaurelB branch from 5459aa7 to ba9800c Compare January 22, 2025 05:08
Changelog:
- Use Command syntax.
- Replace `_()` by `self.env._()`.
- Rename the method `_fetch_duplicate_supplier_reference` to
  `_fetch_duplicate_reference` to include both sale and purchase
  documents.
- Add context validation to mute the warning when executing the
  `_prepare_sequence_current_moves` method without moves in the
  journals, allowing the warning to be muted when the method is executed
  in the `post_init_hook`.
- 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 and chain to increase
  coverage.

Co-authored-by: Bert Van Groenendael <[email protected]>
Co-authored-by: oury.balde <[email protected]>
@CLaurelB CLaurelB force-pushed the 18.0-mig-account_move_name_sequence-CLaurelB branch from ba9800c to eb9c714 Compare January 22, 2025 05:56
@CLaurelB CLaurelB requested a review from thienvh332 January 22, 2025 06:00
@@ -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.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the pre-commit suggested change.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that done only after migrating?

cls.date = datetime.now()

cls.journals = cls.misc_journal | cls.purchase_journal | cls.sales_journal
with patch("odoo.models.BaseModel._validate_fields"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's not a trivial change, we could add a coment above explaining what's this for. This because patches are not functionally possible, so I think we should provide an explanation in such cases.

Same in similar cases were patches are applied.

# TODO: Delete payment and journal
moves = env["account.move"].with_context(force_delete=True).browse(move_ids)
payments = moves.payment_ids
moves_without_payments = moves - payments.mapped("move_id")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapped not required

payments.unlink()
if moves_without_payments:
moves_without_payments.button_draft()
moves_without_payments.unlink()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not removing all moves instead of only the ones without payments?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the payments already removes the entries related to them. Therefore, it is only necessary to remove the other moves that were not created from a payment.

env.cr.commit()

def _create_invoice_payment(
self, deadlock_timeout, payment_first=False, ir_sequence_standard=False
):
odoo.registry(self.env.cr.dbname)
Registry(self.env.cr.dbname)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this does nothing.

@@ -344,6 +373,7 @@ def test_sequence_concurrency_95_pay2inv_inv2pay(self):
args=(deadlock_timeout, False, True),
name="Thread invoice payment",
)
self.env.registry.enter_test_mode(self.env.registry.cursor())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be done in the setUpClass method, along with the addClassCleanup to exit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.