-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
[10.0][MIG] product_multi_company #35
[10.0][MIG] product_multi_company #35
Conversation
a1f1894
to
15d7865
Compare
It seems there are some problems with the tests. |
Ahhhh yup I have these modules installed in my local. Fix incoming, simple simple! Weird runbot didn't fail though. |
Am I reading v10 product security right? There's no way for a non-admin user to edit a product without depending on Adding a dependency simply for a test seems like overkill IMO. I almost feel like it would be better to create a new group in the test with proper permissions. Or maybe just edit an existing group. Thoughts? |
3f8c107
to
d36886c
Compare
Hooray editing the security seems to have worked & I don't think will have any side effects due to transaction rollback. This is ready for review. |
product_multi_company/hooks.py
Outdated
template_model = env['product.template'] | ||
groups = template_model.read_group([], ['company_id'], ['company_id']) | ||
for group in groups: | ||
if not group['company_id']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put here # pragma: no cover
as the next line is not important to test and you'll achieve full coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little nitpicking
This is now WIP, I'm about to strip some logic out and move it into |
556a713
to
196b444
Compare
@lasley @pedrobaeza Hello I totally disagree with this PR. From my point of view, it should not depends on #39. For example, in my project I use product-multi-company but I am not interested at all to have active per company. |
@Cedric-Pigeon, if you don't include active mechanism too, you will have usability problems. I have already found that problems, but minimize them with the users, covering the underlying problem. What are your concerns? Performance? |
@pedrobaeza My concern is that my customer don't want this active mechanism. He want a single flag common to all companies. |
Maybe an opt-in/opt-out mechanism inside the same module? What I want to avoid is to have partner_multi_company, partner_multi_company_active, product_multi_company, product_multi_company_active and so on. @lasley what do you think? |
@pedrobaeza I understand your position but I still think we are too far from a simple migration, adding features should be done separatly otherwise backports will be totally impossible. |
Well, if someone do the migration for you, that's not a problem. I also understand your position about solving your specific problem and thus not complicating with other not needed features, but if the architecture is good (which is), migration for both modules (product_multi_company and base_multi_company) is not going to be a problem. Even more, you will reduce the needed code, as part of the logic is shared on base_multi_company. |
@pedrobaeza Sorry for me the architecure is not good. You will multiply queries by 3. |
@pedrobaeza The proposed implementation in #39 would have a serious problem at scale!!!!! (#39 (comment), #39 (comment)) |
@pedrobaeza IMO 'visibility by company' and 'active by company' desserves different purposes and we must be able to choice one and/or other. As commented the proposed architecture will lead to serious performance issue. Since product_multi_company is a requirement for our client and is a central module of our solution we propose to migrate the current implementation from 9.0 to 10.0. The current PR could be rebased on the migrated module once a solution to avoid performance issues and to put in place your opt-in/opt-out mechanism will be found. This approach will let us move forward and benefits to others users of the product_multi_company module. |
I recommend you take a look at how much code I have reduced in this module before stating that a 1:1 migration is the best option. This module and all like it duplicate a bunch of code, and 100% need a base module. I see your point that active by company could not be desired in some instances. I can remove that feature from the #39 base, then just add it into another module. We could still avoid the cascading module issue mentioned by Pedro, because we'd be using a common base and would only need one module to change its operation. TBD whether an enable/disable option is feasible once I come up with a new implementation, but I'll keep that in mind as well. If that works, it can just be an upgrade to the base instead of a new module. |
OK, for me let's go for base_multi_company + product_multi_company depending on it with a lot of duplication removed, and then an extra module base_multi_company_active that adds automatically on all dependent modules (partner_multi_company, product_multi_company...) the active by company feature. |
Just as a note, once the base merges in I will also upgrade |
@lasley @pedrobaeza great for me if you separate active per company in another module. Thanks for your consideration. |
@lasley Could you please remove base_multi_company module form this PR ? |
@Cedric-Pigeon - This PR is dependent on |
@lasley Yes I know I tested it on my own branch with the PR |
196b444
to
65bb528
Compare
========================================== Product permissions for discrete companies ========================================== This modules allows to select in which of the companies you want to use each of the products. Installation ============ This module uses the post and uninstall hooks for updating default product template security rule. This only means that updating the module will not restore the security rule this module changes. Only a complete removal and reinstallation will serve. Usage ===== On the product form view, go to the "Information" tab, and put the companies in which you want to use that product. If none is selected, the product will be visible in all of them. The default value is the current one.
This has been rebased and squashed now that #39 has been merged, and is now ready for review! |
self.product_company_none.sudo(self.user_company_2.id).name = "Test" | ||
|
||
def test_company_1(self): | ||
self.assertEqual(self.product_company_1.company_id, self.company_1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I missed some part of the functionality of this module. Looking here we are operating on the product.product
, but we have implemented on product.template
.
Is the intent of this module to distribute the companies to the variants too? In my case this is less than ideal, because the variants are owned by the companies themselves. Are there cases I am not considering, in which the variants would be owned by multiple companies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lasley yes we have cases where the variants are owner by multiple companies...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lmignon The same companies in all instances?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I have to design this. My use case is not quite so simple, and requires isolated company sets. I've set some time next week for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lasley I investigated deeper your problem. This line has no chance to succeed because the user on self.product_company_1
is admin and its company is not self.company_1
but main company. I think the test should be self.assertEqual(self.product_company_1.sudo(self.user_company_1).company_id, self.company_1)
because in base_multi_company, the company_id
field is computed based on the user of self.env
.
Another way to solve it is to create product_company_1
with self.user_company_1
in the setUp method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
_logger = logging.getLogger(__name__) | ||
|
||
try: | ||
from odoo.addons.base_multi_company import hooks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isnot this redundant with the dependency in manifest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is- but if for some reason the module isn't there, Odoo will fail to start.
@lasley Could you check why tests are failing ? |
@Cedric-Pigeon - tests are failing due to the product variant discussion here |
self.product_company_none.sudo(self.user_company_2.id).name = "Test" | ||
|
||
def test_company_1(self): | ||
self.assertEqual(self.product_company_1.company_id, self.company_1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lasley I investigated deeper your problem. This line has no chance to succeed because the user on self.product_company_1
is admin and its company is not self.company_1
but main company. I think the test should be self.assertEqual(self.product_company_1.sudo(self.user_company_1).company_id, self.company_1)
because in base_multi_company, the company_id
field is computed based on the user of self.env
.
Another way to solve it is to create product_company_1
with self.user_company_1
in the setUp method.
self.product_company_2.sudo(self.user_company_1).name = "Test" | ||
|
||
def test_company_2(self): | ||
self.assertEqual(self.product_company_2.company_id, self.company_2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue here, the test should be self.assertEqual(self.product_company_2.sudo(self.user_company_2).company_id, self.company_2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh yes how could I forget the fancy new computation?! Good call 😄
2a661bf
to
bad0856
Compare
This PR should be good to go now. Note - I am now proposing a module rename to I will be submitting a new module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for me
Why don't you put both functionalities in this module? |
@pedrobaeza - In this module, the template and variant operate in identical fashion in respect to the companies. It was stated that the product variants and templates need to be aligned in this convo. While it was mentioned that this need only be the default operation, I need something that is fairly at odds with this module. In my case, I require the template companies to be completely separate from the variant companies. A company with access to the variant will only receive read access to the template, unless that company is also in the template's companies. This will effectively allow for management of the template by Company A, while the variants are managed by their individual companies (Variant 1 by Company B, Variant 2 by Companies C and D). Think of something like amazon.com's marketplace, where the UPCs are primarily controlled by Amazon, but some aspects of the posted product are controlled by the vendor. In order to make this operate, my solution is to simply implement |
@pedrobaeza I completely agree with @lasley I think it should be split to a more specific module |
@Cedric-Pigeon @lmignon - How are you guys currently handling pricelists? Looking at this code, I feel like there should be massive security issues: <record model="ir.rule" id="product_pricelist_comp_rule">
<field name="name">product pricelist company rule</field>
<field name="model_id" ref="model_product_pricelist"/>
<field name="global" eval="True"/>
<field name="domain_force"> ['|',('company_id','=',user.company_id.id),('company_id','=',False)]</field>
</record>
<record model="ir.rule" id="product_pricelist_item_comp_rule">
<field name="name">product pricelist item company rule</field>
<field name="model_id" ref="model_product_pricelist_item"/>
<field name="global" eval="True"/>
<field name="domain_force"> ['|',('company_id','=',user.company_id.id),('company_id','=',False)]</field>
</record> Edit: added the code, whoops |
Oh snap nevermind, seems they work just fine. Makes sense in hindsight, they just restrict by company & there would be no reason for multiple companies to sell them! So yeah, I think this is good for merge - unless there's disagreement on the name change? I'll squash after confirmation & before merge - there's a few logical commits in here that we don't want to lose. |
I prefer then to keep this one as product_multi_company, which is the usual way of working, and call the other module product_variant_multi_company, following same convention as the one used in https://github.com/OCA/product-variant |
@pedrobaeza - renamed back to product_multi_company |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash at your taste and I'll merge.
@lasley I think it should be a good idea to include record rules on product_template and product_product don't you ? |
* Rename manifest * Change openerp references to odoo * Bump version * Add pragma no cover * Edit security of product employee to allow writes (in tests) * Fix permissions in tests * Fix domain & add test * Implement base_multi_company on product_multi_company * Add related cols for product variant
@Cedric-Pigeon - record rules are applied and removed by the base hooks @pedrobaeza - squashed! |
b74e821
to
ab61142
Compare
@lasley the product.product rule is missing as @Cedric-Pigeon says. |
@pedrobaeza - I don't see a product.product rule to update. |
Wait thinking about it further - the company_id and company_ids is being implemented on the template. Wouldn't the security rules implicitly pass through due to the inheritance? I will need to create a new rule in my product.product module, but I think we're fine here. You guys have been using this previously with no security issues, yes? |
Yeah, you're right, I didn't remember that part. Indeed the security rule is inherited. Merging... |
Migration of
product_multi_company
to v10This depends on