[IMP] account: warn when the sequence format changed
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/odoo#74326 X-original-commit: 56f7afb253da6560cddae121f5b6cdab3e3b1c6e Signed-off-by: Laurent Smet <smetl@users.noreply.github.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -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"
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -1190,6 +1190,47 @@ class AccountMove(models.Model):
|
||||
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:
|
||||
|
||||
@@ -79,12 +79,22 @@ class TestSequenceMixin(AccountTestInvoicingCommon):
|
||||
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')
|
||||
|
||||
|
||||
@@ -2135,6 +2135,7 @@ class Form(object):
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user