-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Pass context to other models when fetching more data #69
base: master
Are you sure you want to change the base?
Conversation
@@ -316,6 +316,7 @@ def _create_model_class(self, model): | |||
fields_get = self._odoo.execute(model, 'fields_get') | |||
for field_name, field_data in fields_get.items(): | |||
if field_name not in FIELDS_RESERVED: | |||
field_data['context'] = self._context # pass context to new fields ... |
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.
Hi, thanks for contributing.
Could you please share the use case that need to add context to field data
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.
Hi @flotho,
In the following sample code (some bits are redundant, they're extracted from a longer chunk of code..), using a vanilla odoorpc==0.8.0, you will get term_id = False and fiscal_pos_id = False.
Using this proposed patch, you will get the id corresponding to the requested property, depending on the requested company_id.
creds['companyid'] = <sample company_id>
rp = odoo.env['res.partner']
rp_list = rp.with_context(allowed_company_ids=[creds['companyid']])
move_part = rp_list.browse([<sample partner_id>])
term_id = move_part.with_context(company=creds['companyid']).property_payment_term_id.id
fiscal_pos_id = move_part.with_context(company=creds['companyid']).property_account_position_id.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.
Hope my approach is the right one ! If I've missed something, don't hesitate to correct me.
Best regards,
Arnaud
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.
thanks, more clear and very useful
@@ -316,6 +316,7 @@ def _create_model_class(self, model): | |||
fields_get = self._odoo.execute(model, 'fields_get') | |||
for field_name, field_data in fields_get.items(): | |||
if field_name not in FIELDS_RESERVED: | |||
field_data['context'] = self._context # pass context to new fields ... |
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.
thanks, more clear and very useful
Why is this not merged yet ? |
When OdooRPC dynamically fetches more information (i.e. when accessing .partner_id.name), if the instance has been instantiated using
with_context
, this context is not passed along and can lead to unwanted results (i.e when using with_context(allowed_company_ids=[1,2,3]))This fix allows to pass such context information.