Hi i have created a field named as count_books by inheritace after creating the field it is shown in the model
of odoo but when i search in the pgadmin table(res_partner) the field is not there can anybody help me regarding this.
here is the code:
class ResPartner(models.Model):
_inherit = 'res.partner'
published_book_ids = fields.One2many(
'library.book', 'publisher_id',
string='Published Books')
authored_book_ids = fields.Many2many(
'library.book',
string='Authored Books',
)
count_books = fields.Integer('Number of Authored Books',compute='_compute_count_book')
@api.depends('authored_book_ids')
def _compute_count_book(self):
for b in self:
b.count_books = len(b.authored_book_ids)
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
Hi Usuma Gull,
It's because your field is compute. Compute field are not store in the DB.
If you want to store it you have to add the parameter store=true.
count_books = fields.Integer('Number of Authored Books',compute='_compute_count_book',store=True)
The computed fields by default are not stored in DB and they are computed and returned when requested. That's mean you can show it in Odoo views and it will be readonly and you can search by it in Odoo UI but you can enable searching and setting value by setting the search and inverse parameters.
If you want to store it in DB, you want to add store=True and add depends fields in api.depends in computed method so once of the depends fields is changed the computed field will be recalculated and you can search it in Odoo UI.
Computed filed is not store by default.
just add store=True in your field
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
2
aug. 23
|
3125 | ||
|
3
dec. 22
|
33753 | ||
|
1
mrt. 15
|
4965 | ||
Inheriting attributes from Fields
Opgelost
|
|
1
feb. 23
|
7899 | |
|
7
dec. 23
|
26148 |
but it is showing in the odoo model it mean compute fields can be seen in the odoo models?