ERP-Ukraine / odoo-repository-dart

Dart package of generic Odoo repository
MIT License
17 stars 16 forks source link

Do we need to override `search_read` method for every Odoo models? #9

Open digitalsatori opened 1 year ago

digitalsatori commented 1 year ago

Thank you @lem8r for your awesome project. I'm learning flutter now.

It seems the original search_read method can only read id and __last_update fields. When I assign more fields in the oFields property of my implementation of model specific OdooRecord, it won't pick up by the original search_read. thus, I have to override the existing search_read and put in the needed oFields from the given type.

Is this a known limitation? or do I misunderstood anything?

Sorry for opening an issue for just a question.

lem8r commented 1 year ago

Hi,

Well, it should work as shown in the example. You define list of fields that should be fetched for specific model and base class should do the job. However linter says that overriding fields should be avoided so oFields and others will be replaces with getters that should be overridden.

digitalsatori commented 1 year ago

Thanks for your reply. I tried both the examples for res.user in example folder and the res.partner example in ReadMe. The res.user example comes with an overrided searchRead, it is running OK, while for the res.partner example, when I run the app, it prompts a Type error to show that the name field has a value of null, which can not be converted to a valid record value.

I traced down the code a bit. It seems that the oFields getter on the PartnerRecord is not used when fetching data from Odoo, instead, the original oFields on OdooRecord class with the value of ['id', '__last_update'] is used, thus the null value for partner name.

I've tried the following to circumvent the problem. Pass the fields list through constructor param of OdooRepository class (adding a param on the said class) or overriding a getter for oFields on OdooRepository class , and use oFields instead of OdooRecord.oFields in the searchRead method on the OdooRepository class.

Both ways worked without overriding searchRead method in extended classes, but I'm not sure whether there is a better way.