I've try this:
[('company_id','=',company_id)]
self.env.company_id
self.env.user.company_id
But those all 3 ways are leaded to default company, but not current company.
I've try this:
[('company_id','=',company_id)]
self.env.company_id
self.env.user.company_id
But those all 3 ways are leaded to default company, but not current company.
I suggest creating a related
field that points to the current company or just creating a new stored computed field show_field_XY
. In the _compute method you can access the context like this:
self.env.context.get('company_id')
Finally, just access that field in the domain and you should be good to go.
try this
current_company = self.env.user.company_id
As i check, if we use context to get current company, and in case we using multi company, we can only get the first company.
In that case, we should use company_ids to get all the companies of user instead.
Example:
['|',('company_id','in',company_ids),('company_id','=',False)]
Hope it's help.
Have you tried self.env.company
? You could use a separate field to determine this and use that in your xml..
active_company_id = fields.Many2one(
"res.company",
string="Company",
default=lambda self: self.env.company,
)
You should create record rules for your module like the following,
and make sure in your class model you have the company_id
set up already:
<!-- Rules --><record id="yourmodullid_comp_rule" model="ir.rule"><field name="name">""" multi-company</field><field name="model_id" ref="model_yourmodel" /><field name="domain_force">['|',('company_id', 'in', company_ids),('company_id','=',False)]</field></record><!-- ___________ -->