diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 7e9db1039a8..dfd2f1bff9a 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -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.*?)(?P\\d*)(?P\\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 diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 614690d172f..f702ad67fe4 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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: diff --git a/addons/account/tests/test_sequence_mixin.py b/addons/account/tests/test_sequence_mixin.py index 63705950ec2..bd0566f252b 100644 --- a/addons/account/tests/test_sequence_mixin.py +++ b/addons/account/tests/test_sequence_mixin.py @@ -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') diff --git a/odoo/tests/common.py b/odoo/tests/common.py index 1877324f63c..3f47ed82e7a 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -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)