-
-
Notifications
You must be signed in to change notification settings - Fork 238
[18.0][IMP] sale_order_product_recommendation_product_sold_by_delivery_week: show live per-customer weekly sales in catalog #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CarlosRoca13
wants to merge
1
commit into
OCA:18.0
Choose a base branch
from
Tecnativa:18.0-IMP-sale_order_product_recommendation_product_sold_by_delivery_week
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
sale_order_product_recommendation_product_sold_by_delivery_week/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from . import models | ||
| from . import wizard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
sale_order_product_recommendation_product_sold_by_delivery_week/models/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import product_product |
52 changes: 52 additions & 0 deletions
52
sale_order_product_recommendation_product_sold_by_delivery_week/models/product_product.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Copyright 2026 Tecnativa - Carlos Roca | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class ProductProduct(models.Model): | ||
| _inherit = "product.product" | ||
|
|
||
| weekly_sold_delivered_catalog_shown = fields.Char( | ||
| string="Weekly Sold for Catalog", | ||
| compute="_compute_weekly_sold_delivered_catalog_shown", | ||
| groups="sales_team.group_sale_salesman", | ||
| ) | ||
|
|
||
| def _weekly_sold_delivered_shown_map(self, partner): | ||
| """Return ``{product: formatted weekly string}`` for ``self`` computed | ||
| live and filtered by ``partner`` (its commercial partner). Services are | ||
| skipped.""" | ||
| products = self.filtered(lambda p: p.type != "service") | ||
| if not products or not partner: | ||
| return {} | ||
| products_weekly = products.with_context( | ||
| weekly_partner_id=partner.id, | ||
| )._weekly_sold_delivered() | ||
| return { | ||
| product: self._format_weekly_string(products_weekly.get(product, False)) | ||
| for product in products | ||
| } | ||
|
|
||
| def _get_catalog_weekly_partner(self): | ||
| """Return the partner to filter the weekly sales by when the product | ||
| catalog is opened from a sale order, so the hint matches the | ||
| recommendation wizard. Empty recordset in any other context.""" | ||
| if self.env.context.get("product_catalog_order_model") != "sale.order": | ||
| return self.env["res.partner"] | ||
| order_id = self.env.context.get("product_catalog_order_id") | ||
| if not order_id: | ||
| return self.env["res.partner"] | ||
| order = self.env["sale.order"].browse(order_id).exists() | ||
| return order.partner_id.commercial_partner_id | ||
|
|
||
| @api.depends_context("product_catalog_order_model", "product_catalog_order_id") | ||
| def _compute_weekly_sold_delivered_catalog_shown(self): | ||
| """Live, customer-filtered weekly sales hint that replaces, in the | ||
| product catalog opened from a sale order, the globally stored hint added | ||
| by ``product_sold_by_delivery_week``.""" | ||
| self.weekly_sold_delivered_catalog_shown = False | ||
| weekly_map = self._weekly_sold_delivered_shown_map( | ||
| self._get_catalog_weekly_partner() | ||
| ) | ||
| for product in self: | ||
| product.weekly_sold_delivered_catalog_shown = weekly_map.get(product, False) | ||
1 change: 1 addition & 0 deletions
1
...der_product_recommendation_product_sold_by_delivery_week/readme/CONTRIBUTORS.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| - [Tecnativa](https://www.tecnativa.com): | ||
| - David Vidal | ||
| - David Bañón | ||
| - Carlos Roca | ||
| - Jairo Llopis ([Moduon](https://www.moduon.team)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
sale_order_product_recommendation_product_sold_by_delivery_week/views/product_views.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <!-- Copyright 2026 Tecnativa - Carlos Roca | ||
| License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
| <odoo> | ||
| <record id="product_view_kanban_catalog" model="ir.ui.view"> | ||
| <field name="model">product.product</field> | ||
| <field | ||
| name="inherit_id" | ||
| ref="product_sold_by_delivery_week.product_view_kanban_catalog" | ||
| /> | ||
| <field name="arch" type="xml"> | ||
| <!-- Replace the globally stored hint with the live, customer-filtered | ||
| one so the catalog matches the recommendation wizard. --> | ||
| <field name="weekly_sold_delivered_shown" position="after"> | ||
| <field | ||
| groups="product_sold_by_delivery_week.group_weekly_selling_order_line" | ||
| name="weekly_sold_delivered_catalog_shown" | ||
| /> | ||
| </field> | ||
| <field name="weekly_sold_delivered_shown" position="attributes"> | ||
| <attribute name="invisible">1</attribute> | ||
| </field> | ||
| </field> | ||
| </record> | ||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this fit in the base module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that there's no hard technical dependency: the catalog field doesn't use anything from sale_order_product_recommendation and the base module already has the catalog view and the weekly_partner_id filtering, so it could live there.
I kept it in the glue module on purpose, though. Its only reason to exist is to make the catalog match the recommendation wizard. And the base field is intentionally stored + cron-refreshed for performance, showing a global hint; moving this in would force a live, per-customer recompute on every catalog open for everyone using only the base module, changing its behavior and performance. So the field belongs where the "match the wizard" intent lives.
If you'd still prefer the global catalog hint to be live/per-customer for base users too, I can move the field + view there instead.