Comments (9)
Probably... Usual optimization techniques are read_group
or search_count
.
from brand.
Probably... Usual optimization techniques are
read_group
orsearch_count
.
Thanx for quick reply. Would you please care to elaborate a bit on how to apply the mentioned? The _compute_products_count
only does this:
@api.depends("product_ids")
def _compute_products_count(self):
for brand in self:
brand.products_count = len(brand.product_ids)
I'd thought this would produce simple SQL query but obviously it is doing something more. I guess from the time it takes it somehow does a query for each Product with that Brand applied. Should I maybe use search_count
in this method instead of what is there currently?
from brand.
It's caching all products data (more or less). You can do something similar (simpler in this case) to:
from brand.
It's caching all products data (more or less). You can do something similar (simpler in this case) to:
Yes but that's reading the objects and actually using them. AFAIK I do not need to load them just count them. So I guess I should use search_count
in _compute_products_count
implementation? Will try.
from brand.
Thanx @pedrobaeza The solution is quite simple. I create a module where I overrode the method to be like this:
class ProductBrand(models.Model):
_inherit = "product.brand"
@api.depends("product_ids")
def _compute_products_count(self):
contract_model = self.env['product.template']
for brand in self:
brand.products_count = contract_model.search_count([('product_brand_id', '=', brand.id)])
Is that correct?
from brand.
Yes, that's it
from brand.
Was asking just to be sure I do not miss anything. Does it make any sense to create PR and change the main module with this code?
from brand.
Yes, please go with the pr
from brand.
OK, will. Thanx for help, closing this one.
from brand.
Related Issues (20)
- Migration to version 16.0 HOT 5
- Missing dependency in sale_brand? HOT 5
- SyntaxError: each UNION query must have the same number of columns, when POS_sale module is active HOT 6
- [16.0] Update to `transfer_field_to_modifiers` in Odoo Core HOT 1
- [15.0] [16.0] "web.report_assets_common" defined for non-existing file in brand_external_report_layout HOT 1
- Brand "Create new" missing HOT 4
- Brand missing on create account.move HOT 4
- [16.0][BUG][brand_external_report_layout] is_company_details_empty missing HOT 4
- [16.0] brand_external_report_layout : can't be used in multi-company context and conflicts with other modules HOT 1
- Migration to version 17.0 HOT 2
- Error in previsualizing layout and printing invoices HOT 1
- "Post Journal Entries" in Expenses module returns missing brand if expense is Paid By "Company" HOT 1
- Clicking any brand link on the product_template kanban view results in error HOT 2
- [17.0] brand/product_brand: Just installing the following DeprecationWarning: warning appears.
- [17.0] brand: field brand_use_level does not exist in the model "res.config.settings" HOT 1
- [17.0] brand/product_brand: Error while importing module 'product_brand'.
- Brand not working with POS - Enhancement HOT 5
- No branding on sales documents HOT 5
- product_brand miss a related suppliers field HOT 1
- Migration to version 15.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brand.