[FIX] account: validate the correct order of the account report lines
Issue Description When a user changes the sequence of the lines which have a parent_id field, particularly when it changes the sequence and the parent field of the line is after the line, then it will give an error in the opening of the reports. Steps to Reproduce: [This step is only used for this traceback. But the issue occurs in all the account reports.] 1. Install the account_reports module. 2. Open accounting and go to configuration. 3. Then, click on accounting reports and select the profit and loss report. 4. Change the sequence of the lines. 5. Save the changes. 6. Click on the reporting menu and select the profit and loss report. 7. The traceback will generate. Fix: This commit resolves the above issue by throwing a validation exception when the parent line is set after the line. And also throws a validation exception when the user sets the parent line as itself. Sentry ID: 3944989529 closes odoo/odoo#128209 X-original-commit: a8a147dab40af4732bbe072cfd9cff1d1ba80e36 Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user