Hello odooers & developers,
Its odoo tips and tricks article, where I would like to share more knowledge about the check_company_auto attribute in odoo
as an odoo developer, knowing the fundamentals of check_company_auto attribute in odoo behaviour, its Syntax, and how we can use the check_company_auto attribute in odoo is essential.
Explore check_company_auto attribute in odoo :-
- In Odoo, when managing multiple companies within a single database, ensuring data consistency across these companies is crucial. The _check_company_auto attribute provides a powerful tool for achieving this by automatically verifying that related records belong to the same company.
- When you define a model class with _check_company_auto set to True, Odoo automatically performs company checks during record creation (create()) and modification (write()). This includes verifying that any relational fields (e.g., many2one, one2many) in your model point to records belonging to the same company as the current record.
Use of check_company_auto attribute in odoo :-
- Usecase: When the user attempts to create a SaleOrder for Company A and selects a vendor from Company B, Odoo automatically triggers a company check, raising an error that prevents saving the record until the vendor_id is corrected to a supplier belonging to Company A.
Check_company_auto attribute
.py
class MyModel(models.Model):
_name = 'my.model'
_check_company_auto = True
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company)
partner_id = fields.Many2one('res.partner', string='Partner', check_company=Tr
# _check_company_auto works best with models that have a company_id field explicitly defined. # Combine _check_company_auto with the check_company attribute in relational field definitions for enhanced control.
If you want specific odoo tips or tricks, please let us know the topic of your tips by mail at [email protected]. Then next, we would like to write a tips article based on your suggested topics, too
Devintellecs & team are odoo services providers in the USA and INDIA, so we will try our best to write the best content on your tips request
if you want to check your odoo technical or functional knowledge, then we have prepared the odoo EXam practice test for the odoo technical & functional people
Thanks, & Stay tuned for the following odoo tips soon...
Understanding the_check_company_auto attribute in Odoo