This question has been flagged
3 Replies
7559 Views

I am looking at the company_depended property and how it works. I am looking at the definitions of it's computed fields:

def _default_company_dependent(self, model):
return model.env['ir.property'].get(self.name, self.model_name)

def _compute_company_dependent(self, records):
Property = records.env['ir.property']
values = Property.get_multi(self.name, self.model_name, records.ids)
for record in records:
record[self.name] = values.get(record.id)


I am really struggling to understand how model and records are passed as arguments to those methods. Basically the definition of computed includes only self without records. So how does that work?

Thanks,
Dimitar





Avatar
Discard
Best Answer

Hi, 

You can see following for this:

https://youtu.be/GkNgc-fZO-I

Hope it helps,

Thanks

Avatar
Discard
Best Answer

In Odoo, computed and default fields are two types of fields that have different functionalities.

A computed field is a field that is not stored in the database, but rather computed or calculated on the fly when it is needed. The value of a computed field is calculated by a function, which is specified using the @api.depends decorator. The function is executed every time the value of one of the fields listed in the @api.depends decorator changes.

For example, let's say we have a model called Product with two fields price and discount. We want to compute the discounted price of the product based on the price and the discount. We can create a computed field called discounted_price and define a function that calculates its value based on the values of price and discount.

A default field, on the other hand, is a field that is stored in the database, but has a default value assigned to it. The default value is assigned when a new record is created, and can be a static value, a dynamic value based on the current date or time, or a value based on the value of another field in the same record.

For example, let's say we have a model called Customer with a field called date_joined. We want to assign a default value to date_joined that is the current date and time. We can create a default field called date_joined and define a function that returns the current date and time.

In summary, computed fields are calculated on the fly and not stored in the database, while default fields have a default value assigned to them and are stored in the database.

Avatar
Discard
Best Answer

I am also interested in the answer for your question :)

Avatar
Discard