Skip to content

Commit

Permalink
[IMP] account: warn when the sequence format changed
Browse files Browse the repository at this point in the history
Explain the situation when a manual change has been done to the sequence
of `account.move`. This was needed because some user didn't realize that
they changed the sequence, and when they realized it, it had polluted
multiple numbers after that.

closes odoo#74326

X-original-commit: 56f7afb
Signed-off-by: Laurent Smet <[email protected]>
Signed-off-by: William André (wan) <[email protected]>
  • Loading branch information
william-andre committed Jul 28, 2021
1 parent f8137cf commit 5bc3741
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
38 changes: 38 additions & 0 deletions addons/account/i18n/account.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6841,6 +6841,12 @@ msgid ""
" entry. You should create the credit note manually instead."
msgstr ""

#. module: account
#: code:addons/account/models/account_move.py:0
#, python-format
msgid "It was previously '%(previous)s' and it is now '%(now)s'."
msgstr ""

#. module: account
#: model_terms:ir.ui.view,arch_db:account.view_move_form
msgid "JRNL/2016/00001"
Expand Down Expand Up @@ -12840,6 +12846,12 @@ msgid ""
"applied."
msgstr ""

#. module: account
#: code:addons/account/models/account_move.py:0
#, python-format
msgid "The sequence format has changed."
msgstr ""

#. module: account
#: code:addons/account/models/sequence_mixin.py:0
#, python-format
Expand All @@ -12848,6 +12860,32 @@ msgid ""
"^(?P<prefix1>.*?)(?P<seq>\\d*)(?P<suffix>\\D*?)$"
msgstr ""

#. module: account
#: code:addons/account/models/account_move.py:0
#, python-format
msgid ""
"The sequence will never restart.\n"
"The incrementing number in this case is '%(formatted_seq)s'."
msgstr ""

#. module: account
#: code:addons/account/models/account_move.py:0
#, python-format
msgid ""
"The sequence will restart at 1 at the start of every month.\n"
"The year detected here is '%(year)s' and the month is '%(month)s'.\n"
"The incrementing number in this case is '%(formatted_seq)s'."
msgstr ""

#. module: account
#: code:addons/account/models/account_move.py:0
#, python-format
msgid ""
"The sequence will restart at 1 at the start of every year.\n"
"The year detected here is '%(year)s'.\n"
"The incrementing number in this case is '%(formatted_seq)s'."
msgstr ""

#. module: account
#: code:addons/account/wizard/account_resequence.py:0
#, python-format
Expand Down
41 changes: 41 additions & 0 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,47 @@ def _onchange_name_warning(self):
else:
self.show_name_warning = False

origin_name = self._origin.name
if not origin_name or origin_name == '/':
origin_name = self.highest_name
if self.name and self.name != '/' and origin_name and origin_name != '/':
new_format, new_format_values = self._get_sequence_format_param(self.name)
origin_format, origin_format_values = self._get_sequence_format_param(origin_name)

if (
new_format != origin_format
or dict(new_format_values, seq=0) != dict(origin_format_values, seq=0)
):
changed = _(
"It was previously '%(previous)s' and it is now '%(current)s'.",
previous=origin_name,
current=self.name,
)
reset = self._deduce_sequence_number_reset(self.name)
if reset == 'month':
detected = _(
"The sequence will restart at 1 at the start of every month.\n"
"The year detected here is '%(year)s' and the month is '%(month)s'.\n"
"The incrementing number in this case is '%(formatted_seq)s'."
)
elif reset == 'year':
detected = _(
"The sequence will restart at 1 at the start of every year.\n"
"The year detected here is '%(year)s'.\n"
"The incrementing number in this case is '%(formatted_seq)s'."
)
else:
detected = _(
"The sequence will never restart.\n"
"The incrementing number in this case is '%(formatted_seq)s'."
)
new_format_values['formatted_seq'] = "{seq:0{seq_length}d}".format(**new_format_values)
detected = detected % new_format_values
return {'warning': {
'title': _("The sequence format has changed."),
'message': "%s\n\n%s" % (changed, detected)
}}

def _get_last_sequence_domain(self, relaxed=False):
self.ensure_one()
if not self.date or not self.journal_id:
Expand Down
14 changes: 12 additions & 2 deletions addons/account/tests/test_sequence_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,22 @@ def test_journal_sequence(self):
copy2.journal_id = new_journal
self.assertEqual(copy2.name, 'MISC2/2016/01/0001')
with Form(copy2) as move_form: # It is editable in the form
move_form.name = 'MyMISC/2016/0001'
with mute_logger('odoo.tests.common.onchange'):
move_form.name = 'MyMISC/2016/0001'
self.assertIn(
'The sequence will restart at 1 at the start of every year',
move_form._perform_onchange(['name'])['warning']['message'],
)
move_form.journal_id = self.test_move.journal_id
self.assertEqual(move_form.name, '/')
move_form.journal_id = new_journal
self.assertEqual(move_form.name, 'MISC2/2016/01/0001')
move_form.name = 'MyMISC/2016/0001'
with mute_logger('odoo.tests.common.onchange'):
move_form.name = 'MyMISC/2016/0001'
self.assertIn(
'The sequence will restart at 1 at the start of every year',
move_form._perform_onchange(['name'])['warning']['message'],
)
copy2.action_post()
self.assertEqual(copy2.name, 'MyMISC/2016/0001')

Expand Down
1 change: 1 addition & 0 deletions odoo/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ def _perform_onchange(self, fields):
for k, v in values.items()
if k in self._view['fields']
)
return result

def _onchange_values(self):
return self._onchange_values_(self._view['fields'], self._values)
Expand Down

0 comments on commit 5bc3741

Please sign in to comment.