Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0][FIX] Compatibility with multicompany #327

Closed

Conversation

JordiBForgeFlow
Copy link
Sponsor Member

  • The mis.report.instance should allow to define as many
    companies as the user is allowed to operate on when logged.
  • The company is only a required field if the flag 'multi_company' is not set.

@OCA-git-bot
Copy link
Contributor

Hi @sbidoul,
some modules you are maintaining are being modified, check this out!

@JordiBForgeFlow JordiBForgeFlow force-pushed the 13.0-mis_builder-fix-multicompany branch 2 times, most recently from 0894222 to 1fe2deb Compare October 27, 2020 11:13
@@ -4,7 +4,7 @@
<field name="name">Mis Report Instance multi company</field>
<field name="model_id" ref="model_mis_report_instance" />
<field name="domain_force">
['|',('company_id','=',False),('company_id','in',company_ids)]
['|',('company_id','=',False),('company_id','in',company_ids), '|', ('company_ids', '=', False), ('company_ids', 'in', company_ids)]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
['|',('company_id','=',False),('company_id','in',company_ids), '|', ('company_ids', '=', False), ('company_ids', 'in', company_ids)]
['&amp;', '|',('company_id','=',False),('company_id','in',company_ids), '|', ('company_ids', '=', False), ('company_ids', 'in', company_ids)]

and run pre-commit

- The mis.report.instance should allow to define as many
  companies as the user is allowed to operate on when logged.
- The company is only a required field if the flag 'multi_company' is not set.
@LoisRForgeFlow LoisRForgeFlow force-pushed the 13.0-mis_builder-fix-multicompany branch from 1fe2deb to 3072118 Compare January 14, 2021 08:23
@sbidoul sbidoul added the 13.0 label Jan 14, 2021
@LoisRForgeFlow LoisRForgeFlow force-pushed the 13.0-mis_builder-fix-multicompany branch from bc9f39e to a208aed Compare January 14, 2021 14:26
@LoisRForgeFlow
Copy link
Contributor

To ease the review, I will showcase a bit the changes:

  1. When the companies field is empty, the same report can be used for all companies, and you just need to activate more companies if you want to aggregate:
    Base report instance:
    image

If we open this report with only one company active we get the result for each one:
image
image
image

Then we can activate the second and third company to get the aggregated result:
image

  1. Regarding _onchange_company the new behavior can be observer in the gif below:
    Peek 2021-01-14 15-27

@LoisRForgeFlow
Copy link
Contributor

LoisRForgeFlow commented Jan 14, 2021

@sbidoul What do you think? does this make sense to you?

@sbidoul
Copy link
Member

sbidoul commented Jan 14, 2021

To ease the review, I will showcase a bit the changes:

Thanks a lot for this! I'll look into it as soon as possible.

@LoisRForgeFlow
Copy link
Contributor

@sbidoul Any chance you can consider this changes? Thanks!

@sbidoul
Copy link
Member

sbidoul commented Apr 16, 2021

@LoisRForgeFlow yeah I absolutely need to find an hour to focus on this. I'll keep it on the topmost part of my stack.

@LoisRForgeFlow
Copy link
Contributor

@sbidoul Hi, just a friendly reminder. It would be great if you can give your opinion on this!

@sbidoul
Copy link
Member

sbidoul commented Jul 23, 2021

I've reserved some time for MIS builder maintenance mid august. I'll get to it then. Sorry again for the delay.

@sbidoul sbidoul mentioned this pull request Aug 13, 2021
3 tasks
self.company_ids = False

@api.depends("multi_company", "company_id", "company_ids")
def _compute_query_company_ids(self):
for rec in self:
if rec.multi_company:
rec.query_company_ids = rec.company_ids or rec.company_id
# If no companies defined use active companies.
rec.query_company_ids = rec.company_ids or self.env.companies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better here to do the intersection of rec.company_ids and self.env.companies. Because in the report we print the list of companies used in the report and we should not print companies to which the user does not have access and therefore ignored by the record rules.

@@ -163,6 +163,7 @@
<field
name="company_id"
groups="base.group_multi_company"
attrs="{'required': [('multi_company', '=', False)]}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, invisible if multi_company is True ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a better UX, let's take the opportunity to move the multi_company checkbox before the company_id field.

)
multi_company = fields.Boolean(
string="Multiple companies",
help="Check if you wish to specify "
"children companies to be searched for data.",
"several companies to be searched for data.",
default=False,
)
company_ids = fields.Many2many(
comodel_name="res.company",
string="Companies",
help="Select companies for which data will be searched.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help="Select companies for which data will be searched.",
help="Select companies for which data will be searched (search all companies if empty).",

default=False,
)
company_ids = fields.Many2many(
comodel_name="res.company",
string="Companies",
help="Select companies for which data will be searched.",
domain=lambda self: [("id", "in", self.env.companies.ids)],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitate about this domain.

This domain hides companies that are not in the user context. In a way this is good because this is what the report will filter on. But OTOH it would be good to show the user that the report can work also on other companies if they select them in their context.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this domain and add query_company_ids to the view as Effective companies.

@sbidoul
Copy link
Member

sbidoul commented Aug 13, 2021

So I implemented my suggestions in #374 - apologies again for the late review.

@sbidoul sbidoul added this to the 4.0 milestone Aug 14, 2021
@sbidoul
Copy link
Member

sbidoul commented Sep 30, 2021

Superseded by #374

@sbidoul sbidoul closed this Sep 30, 2021
@LoisRForgeFlow LoisRForgeFlow deleted the 13.0-mis_builder-fix-multicompany branch September 30, 2021 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants