Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions odoorpc/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Copy link
Member

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

Copy link
Author

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

Copy link
Author

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

Copy link
Member

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

Field = fields.generate_field(field_name, field_data)
attrs['_columns'][field_name] = Field
attrs[field_name] = Field
Expand Down