Is there any way to filter records with current user's company id in ir.actions.act_window as it doesnt work with "'company_id','=',user.company_id.id" as it says user is not defined which is given. Also ir.rule cannot be used as some of my functions and fields requires other company_id so ir.rule just gives error. Is there any way to do it within xml? or is there any other way?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Buchhaltung
- Lager
- PoS
- Project
- MRP
Diese Frage wurde gekennzeichnet
In Odoo, you cannot directly use user.company_id.id in the domain of ir.actions.act_window because XML does not have access to the user object
XML
<record id="your_action_id" model="ir.actions.act_window">
<field name="name">Your Records</field>
<field name="res_model">your.model</field>
<field name="view_mode">tree,form</field>
<field name="context">{'default_company_id': user.company_id.id}</field>
</record>
PY
from odoo import models, api
class YourModel(models.Model):
_name = 'your.model'
@api.model
def default_get(self, fields):
res = super().default_get(fields)
res['company_id'] = self.env.user.company_id.id
return res
Hi,
Please refer to the code below:
Python
from odoo import models, fields, api
class YourModel(models.Model):
_name = 'your.model'
_description = 'Your Model'
user_company_id = fields.Many2one(
'res.company',
string="User's Company",
compute='_compute_user_company_id',
store=False
)
@api.depends_context('uid')
def _compute_user_company_id(self):
for rec in self:
rec.user_company_id = self.env.company.id
XML:
<record id="action_your_model" model="ir.actions.act_window">
<field name="name">Your Model</field>
<field name="res_model">your.model</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('company_id', '=', user_company_id)]</field>
</record>
Hope it helps.
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!
Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!
RegistrierenVerknüpfte Beiträge | Antworten | Ansichten | Aktivität | |
---|---|---|---|---|
|
0
Dez. 20
|
2121 | ||
|
0
Feb. 25
|
18 | ||
|
1
Nov. 22
|
2097 | ||
|
2
März 15
|
6913 | ||
|
0
März 15
|
3825 |
it is giving error user is not defined
it is ijust giving error user is not defined