diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index e37639c3c09..cef086a7d04 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -8061,6 +8061,22 @@ msgstr "" msgid "Line" msgstr "" +#. module: account +#. odoo-python +#: code:addons/account/models/account_report.py:0 +#, python-format +msgid "Line \"%s\" defines itself as its parent." +msgstr "" + +#. module: account +#. odoo-python +#: code:addons/account/models/account_report.py:0 +#, python-format +msgid "" +"Line \"%s\" defines line \"%s\" as its parent, but appears before it in the " +"report. The parent must always come first." +msgstr "" + #. module: account #: model:ir.model.fields,field_description:account.field_account_report__line_ids msgid "Lines" diff --git a/addons/account/models/account_report.py b/addons/account/models/account_report.py index 98ce6c04b71..e951f5e6fcf 100644 --- a/addons/account/models/account_report.py +++ b/addons/account/models/account_report.py @@ -143,6 +143,16 @@ class AccountReport(models.Model): if report.root_report_id.root_report_id: raise ValidationError(_("Only a report without a root report of its own can be selected as root report.")) + @api.constrains('line_ids') + def _validate_parent_sequence(self): + previous_lines = self.env['account.report.line'] + for line in self.line_ids: + if line.parent_id and line.parent_id not in previous_lines: + raise ValidationError( + _('Line "%s" defines line "%s" as its parent, but appears before it in the report. ' + 'The parent must always come first.', line.name, line.parent_id.name)) + previous_lines |= line + @api.onchange('availability_condition') def _onchange_availability_condition(self): if self.availability_condition != 'country': @@ -286,6 +296,11 @@ class AccountReportLine(models.Model): expression.report_line_id.display_name, )) + @api.constrains('parent_id') + def _check_parent_line(self): + for line in self.filtered(lambda x: x.parent_id == x): + raise ValidationError(_('Line "%s" defines itself as its parent.', line.name)) + def _copy_hierarchy(self, copied_report, parent=None, code_mapping=None): ''' Copy the whole hierarchy from this line by copying each line children recursively and adapting the formulas with the new copied codes.