<commit_before># -*- coding: utf-8 -*-
# Copyright 2015 Eficent Business and IT Consulting Services S.L. -
# <NAME>
# Copyright 2015 Serpent Consulting Services Pvt. Ltd. - <NAME>
# Copyright 2018 ACSONE SA/NV
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from openerp import api, fields, models


class MisReportInstance(models.Model):

    _inherit = 'mis.report.instance'

    operating_unit_ids = fields.Many2many('operating.unit',
                                          string='Operating Unit',
                                          required=False)


class MisReportInstancePeriod(models.Model):

    _inherit = 'mis.report.instance.period'

    operating_unit_ids = fields.Many2many('operating.unit',
                                          string='Operating Unit',
                                          required=False)

    @api.multi
    def _get_additional_move_line_filter(self):
        aml_domain = super(MisReportInstancePeriod, self).\
            _get_additional_move_line_filter()
        if self.report_instance_id.operating_unit_ids:
            aml_domain.append(('operating_unit_id', 'in',
                               self.report_instance_id.operating_unit_ids.ids))
        if self.operating_unit_ids:
            aml_domain.append(('operating_unit_id', 'in',
                               self.operating_unit_ids.ids))
        return aml_domain
<commit_msg>mis_builder_operating_unit: add a sudo in filter<commit_after># -*- coding: utf-8 -*-
# Copyright 2015 Eficent Business and IT Consulting Services S.L. -
# <NAME>
# Copyright 2015 Serpent Consulting Services Pvt. Ltd. - <NAME>
# Copyright 2018 ACSONE SA/NV
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from openerp import api, fields, models


class MisReportInstance(models.Model):

    _inherit = 'mis.report.instance'

    operating_unit_ids = fields.Many2many('operating.unit',
                                          string='Operating Unit',
                                          required=False)


class MisReportInstancePeriod(models.Model):

    _inherit = 'mis.report.instance.period'

    operating_unit_ids = fields.Many2many('operating.unit',
                                          string='Operating Unit',
                                          required=False)

    @api.multi
    def _get_additional_move_line_filter(self):
        aml_domain = super(MisReportInstancePeriod, self).\
            _get_additional_move_line_filter()
        # we need sudo because, imagine a user having access
        # to operating unit A, viewing a report with 3 columns
        # for OU A, B, C: in columns B and C, self.operating_unit_ids
        # would be empty for him, and the query on a.m.l would be only
        # restricted by the record rules (ie showing move lines
        # for OU A only). So the report would display values
        # for OU A in all 3 columns.
        sudoself = self.sudo()
        if sudoself.report_instance_id.operating_unit_ids:
            aml_domain.append(
                ('operating_unit_id', 'in',
                 sudoself.report_instance_id.operating_unit_ids.ids))
        if sudoself.operating_unit_ids:
            aml_domain.append(
                ('operating_unit_id', 'in',
                 sudoself.operating_unit_ids.ids))
        return aml_domain

{'fraction_non_alphanumeric': 0.08698242478403337, 'fraction_numerical': 0.010723860589812333, 'mean_word_length': 2.077910174152154, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6807944', 'n_tokens_mistral': 966, 'n_tokens_neox': 908, 'n_words': 224}