Skip to content

[18.0][MIG] stock_average_daily_sale#481

Open
rousseldenis wants to merge 40 commits into
OCA:18.0from
acsone:18.0-mig-stock_average_daily_sale-dro
Open

[18.0][MIG] stock_average_daily_sale#481
rousseldenis wants to merge 40 commits into
OCA:18.0from
acsone:18.0-mig-stock_average_daily_sale-dro

Conversation

@rousseldenis

Copy link
Copy Markdown
Contributor

No description provided.

@rousseldenis

Copy link
Copy Markdown
Contributor Author

@jbaudoux

@rousseldenis rousseldenis changed the title 18.0 mig stock average daily sale dro [18.0][MIG] stock_average_daily_sale Mar 12, 2026

@jbaudoux jbaudoux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you drop the migrations folder?

@rousseldenis rousseldenis marked this pull request as draft March 12, 2026 14:52
@rousseldenis rousseldenis force-pushed the 18.0-mig-stock_average_daily_sale-dro branch from c660290 to 4a7a4e6 Compare March 12, 2026 15:19
rousseldenis and others added 23 commits March 12, 2026 16:59
…evel + add demo

The configurations are now stored on abc profiles.

Some demo data are loaded in order to show this module features more easily.
By default the priority in odoo is set to '0'. Before this change
the daily sale was never computed for moves done in a normal process.
There is no need to filter out moves based on the priority from
the computation.
Co-authored-by: Jacques-Etienne Baudoux <je@bcim.be>
As tests create a Savepoint, there is a concurrent query when checking the
view existence.
As for x reason, some products appear more than one time in the report,
id generated by the concatenation of product_id and warehouse_id is
irrelevant (as duplicate values possible). Use row_number() instead
Currently translated at 100.0% (58 of 58 strings)

Translation: stock-logistics-reporting-16.0/stock-logistics-reporting-16.0-stock_average_daily_sale
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-reporting-16-0/stock-logistics-reporting-16-0-stock_average_daily_sale/it/
Remove product_abc_classification dependency.
This module is not essential for the current module to function properly.
Only stock_user can see config and report; stock_manager can create and delete config entries
Set default average_daily_sale_root_location on WH create.
Default stock location of the new WH is used for this purpose
Allow to decide if weekends should be included or excluded
in average daily sale calculation.
twalter-c2c and others added 15 commits March 12, 2026 16:59
Take also production location as dest location for daily usage calculation
…ny_id

stock_average_daily_sale:
- add form view for config
- add company_id to config
- allow editing ABC classification level and make sure
  the level is unique per warehouse
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: stock-logistics-reporting-16.0/stock-logistics-reporting-16.0-stock_average_daily_sale
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-reporting-16-0/stock-logistics-reporting-16-0-stock_average_daily_sale/
Currently translated at 100.0% (59 of 59 strings)

Translation: stock-logistics-reporting-16.0/stock-logistics-reporting-16.0-stock_average_daily_sale
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-reporting-16-0/stock-logistics-reporting-16-0-stock_average_daily_sale/it/
- Allow to set a location from which consumption are computed
- Properly compute the average daily quantity
- Add max daily consumption metric
- Remove stock level, this is not relevant for this report
- Drop spike exclusion as it was counter-productive the way it was used
- Moved safety and recommended quantity as computed field so that it can
  be extended
- Added multi-company rules
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: stock-logistics-reporting-16.0/stock-logistics-reporting-16.0-stock_average_daily_sale
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-reporting-16-0/stock-logistics-reporting-16-0-stock_average_daily_sale/
Currently translated at 100.0% (57 of 57 strings)

Translation: stock-logistics-reporting-16.0/stock-logistics-reporting-16.0-stock_average_daily_sale
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-reporting-16-0/stock-logistics-reporting-16-0-stock_average_daily_sale/it/
@rousseldenis rousseldenis force-pushed the 18.0-mig-stock_average_daily_sale-dro branch from 4a7a4e6 to 934b126 Compare March 12, 2026 15:59
@rousseldenis rousseldenis force-pushed the 18.0-mig-stock_average_daily_sale-dro branch from c9fc84f to 27c782c Compare March 13, 2026 06:44
@rousseldenis rousseldenis marked this pull request as ready for review March 13, 2026 06:52
@rousseldenis

Copy link
Copy Markdown
Contributor Author

@jbaudoux ready

@rrebollo rrebollo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe most of the findings are optional, but a few need to be addressed at this point. For all those cases, I've provided a suggestion that should make the change straightforward.

from psycopg2.errors import ObjectNotInPrerequisiteState
from psycopg2.extensions import AsIs

from odoo import _, api, fields, models, registry

@rrebollo rrebollo Mar 23, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from odoo import _, api, fields, models, registry
from odoo import api, fields, models
from odoo.modules.registry import Registry

From OCA Migration Guidelines to v18:

Instead of doing from odoo import registry and then registry(db_name), now you have to do from odoo.modules.registry import Registry and Registry(db_name). More info at odoo/odoo#178784.

Also translations are environment related now.


@api.model
def _check_view(self):
cr = registry(self._cr.dbname).cursor()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cr = registry(self._cr.dbname).cursor()
cr = Registry(self._cr.dbname).cursor()

Idem

Comment on lines +148 to +151
def search(self, domain, offset=0, limit=None, order=None):
if not config["test_enable"] and not self._check_view():
return self.browse()
return super().search(domain=domain, offset=offset, limit=limit, order=order)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider OCA Migration Guidelines? Given this model is really a materialized table I'm guessing this is not relevant. Am I wrong?

If overriding search method for modifying searches result, take into account that this method is not always called in this version. Override search_fetch instead.

class StockAverageDailySaleConfig(models.Model):
_name = "stock.average.daily.sale.config"
_description = "Average daily sales computation parameters"
check_company_auto = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
check_company_auto = True
_check_company_auto = True

Looks like a typo. Anyway I think it's better to address this now.

@rrebollo

rrebollo commented Mar 23, 2026

Copy link
Copy Markdown

Also @rousseldenis, would you be so kind to review my #479 in return?

return self._check_materialize_view_populated(cr)
except ObjectNotInPrerequisiteState:
_logger.warning(
_("The materialized view has not been populated. Launch the cron.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_("The materialized view has not been populated. Launch the cron.")
self.env._("The materialized view has not been populated. Launch the cron.")

@jbaudoux jbaudoux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to improve and refactor this module in v18.0.
I noted as comment what I intend to change

# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Stock Average Daily Sale",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename the module to

Suggested change
"name": "Stock Average Daily Sale",
"name": "Stock Average Daily Usage",

"maintainers": ["jbaudoux"],
"website": "https://github.com/OCA/stock-logistics-reporting",
"depends": [
"sale",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should only depend on stock

"website": "https://github.com/OCA/stock-logistics-reporting",
"depends": [
"sale",
"stock_storage_type_putaway_abc",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to drop this strong dependency and move it to a glue module. Or even better, replace it with a products applicability domain. At the end, it is the only thing that it is doing.

Also it would be better to use the abc product classification level that is at product.product level (abc_storage is only at product.template level) and that supports multi-warehouses through the abc profiles.

"depends": [
"sale",
"stock_storage_type_putaway_abc",
"product_route_mto",

@jbaudoux jbaudoux Apr 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MTO should move to another glue module. It doesn't provide any value to this ADU computation.

New module: stock_average_daily_usage_mto

Comment on lines +67 to +68
nbr_sales = fields.Integer(
string="Number of Sales",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to reflect what it is

Comment on lines +18 to +20
abc_classification_level = fields.Selection(
selection=ABC_SELECTION, required=True, default="b"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move out of this module

@jbaudoux

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants