-
-
Notifications
You must be signed in to change notification settings - Fork 671
[16.0][IMP] pos_product_quick_info: The following improvements have been made: #1440
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
atgalvez08
wants to merge
1
commit into
OCA:16.0
Choose a base branch
from
BinhexTeam:16.0-IMP-pos_product_quick_info
base: 16.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
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
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,2 +1,3 @@ | ||
| from . import product_product | ||
| from . import pos_config | ||
| from . import res_config_settings |
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
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,143 @@ | ||
| from odoo import api, fields, models, _ | ||
| from collections import defaultdict | ||
|
|
||
|
|
||
| class ProductProduct(models.Model): | ||
| _inherit = 'product.product' | ||
|
|
||
| def _get_variant_list(self): | ||
| """Returns a list of product variants grouped by attribute name.""" | ||
| self.ensure_one() | ||
|
|
||
| grouped_values = defaultdict(set) | ||
|
|
||
| for line in self.attribute_line_ids: | ||
| attr_name = line.attribute_id.name | ||
| for value in line.value_ids: | ||
| grouped_values[attr_name].add(value.name) | ||
|
|
||
| variant_list = [] | ||
| for attr_name, values in grouped_values.items(): | ||
| variant_list.append({ | ||
| 'name': attr_name, | ||
| 'values': [ | ||
| { | ||
| 'name': value_name, | ||
| 'search': f'{self.name} {value_name}', | ||
| } | ||
| for value_name in sorted(values) | ||
| ], | ||
| }) | ||
|
|
||
| return variant_list | ||
|
|
||
| def _get_warehouse_list(self): | ||
| """Returns a list of warehouses with overall quantities and details by location.""" | ||
| self.ensure_one() | ||
|
|
||
| product = self | ||
| warehouse_obj = self.env['stock.warehouse'] | ||
| location_obj = self.env['stock.location'] | ||
| quant_obj = self.env['stock.quant'] | ||
| move_obj = self.env['stock.move'] | ||
|
|
||
| warehouses = warehouse_obj.search([]) | ||
|
|
||
| warehouse_list = [] | ||
|
|
||
| for warehouse in warehouses: | ||
| # Total quantities per warehouse using context | ||
| available_qty = product.with_context(warehouse=warehouse.id).qty_available | ||
| forecasted_qty = product.with_context(warehouse=warehouse.id).virtual_available | ||
|
|
||
| # Internal warehouse locations | ||
| internal_locations = location_obj.search([ | ||
| ('usage', '=', 'internal'), | ||
| ('location_id', 'child_of', warehouse.view_location_id.id), | ||
| ]) | ||
| location_ids = internal_locations.ids | ||
|
|
||
| # Stock available by location | ||
| quants = quant_obj.read_group( | ||
| domain=[ | ||
| ('product_id', '=', product.id), | ||
| ('location_id', 'in', location_ids), | ||
| ], | ||
| fields=['quantity', 'location_id'], | ||
| groupby=['location_id'], | ||
| ) | ||
|
|
||
| # Future incoming and outgoing movements | ||
| incoming_moves = move_obj.read_group( | ||
| domain=[ | ||
| ('product_id', '=', product.id), | ||
| ('location_dest_id', 'in', location_ids), | ||
| ('state', 'in', ['confirmed', 'waiting', 'assigned']), | ||
| ], | ||
| fields=['product_uom_qty', 'location_dest_id'], | ||
| groupby=['location_dest_id'], | ||
| ) | ||
|
|
||
| outgoing_moves = move_obj.read_group( | ||
| domain=[ | ||
| ('product_id', '=', product.id), | ||
| ('location_id', 'in', location_ids), | ||
| ('state', 'in', ['confirmed', 'waiting', 'assigned']), | ||
| ], | ||
| fields=['product_uom_qty', 'location_id'], | ||
| groupby=['location_id'], | ||
| ) | ||
|
|
||
| # Index quantities by location | ||
| available_by_location = { | ||
| q['location_id'][0]: q['quantity'] for q in quants | ||
| } | ||
| incoming_by_location = { | ||
| m['location_dest_id'][0]: m['product_uom_qty'] for m in incoming_moves | ||
| } | ||
| outgoing_by_location = { | ||
| m['location_id'][0]: m['product_uom_qty'] for m in outgoing_moves | ||
| } | ||
|
|
||
| # Build list of locations | ||
| location_list = [] | ||
| for loc in internal_locations: | ||
| loc_id = loc.id | ||
| available = available_by_location.get(loc_id, 0.0) | ||
| incoming = incoming_by_location.get(loc_id, 0.0) | ||
| outgoing = outgoing_by_location.get(loc_id, 0.0) | ||
| forecasted = available + incoming - outgoing | ||
|
|
||
| # SOnly show relevant locations (if any exist) | ||
| if available or incoming or outgoing: | ||
| location_list.append({ | ||
| 'name': loc.display_name, | ||
| 'available_quantity': available, | ||
| 'forecasted_quantity': forecasted, | ||
| }) | ||
|
Comment on lines
+61
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, I suggest exploring some built-in resources related to the stock by location request. For example: |
||
|
|
||
| # Build warehouse result | ||
| warehouse_list.append({ | ||
| 'name': warehouse.name, | ||
| 'available_quantity': available_qty, | ||
| 'forecasted_quantity': forecasted_qty, | ||
| 'uom': product.uom_id.name, | ||
| 'locations': sorted(location_list, key=lambda x: x['name']), | ||
| }) | ||
|
|
||
| return warehouse_list | ||
|
|
||
| def get_product_info_pos(self, price, quantity, pos_config_id): | ||
|
|
||
| res = super().get_product_info_pos(price, quantity, pos_config_id) | ||
|
|
||
| pos_config = self.env['pos.config'].browse(pos_config_id) | ||
|
|
||
| # Display warehouses with or without locations according to configuration | ||
| if pos_config.display_product_locations: | ||
| res['warehouses'] = self._get_warehouse_list() | ||
|
|
||
| # Group variants with the same attribute | ||
| res['variants'] = self._get_variant_list() | ||
|
|
||
| return res | ||
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
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 |
|---|---|---|
|
|
@@ -8,10 +8,11 @@ | |
|
|
||
| /* | ||
| :Author: David Goodger ([email protected]) | ||
| :Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ | ||
| :Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ | ||
| :Copyright: This stylesheet has been placed in the public domain. | ||
|
|
||
| Default cascading style sheet for the HTML output of Docutils. | ||
| Despite the name, some widely supported CSS2 features are used. | ||
|
|
||
| See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to | ||
| customize this style sheet. | ||
|
|
@@ -274,7 +275,7 @@ | |
| margin-left: 2em ; | ||
| margin-right: 2em } | ||
|
|
||
| pre.code .ln { color: grey; } /* line numbers */ | ||
| pre.code .ln { color: gray; } /* line numbers */ | ||
| pre.code, code { background-color: #eeeeee } | ||
| pre.code .comment, code .comment { color: #5C6576 } | ||
| pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } | ||
|
|
@@ -300,7 +301,7 @@ | |
| span.pre { | ||
| white-space: pre } | ||
|
|
||
| span.problematic { | ||
| span.problematic, pre.problematic { | ||
| color: red } | ||
|
|
||
| span.section-subtitle { | ||
|
|
@@ -423,7 +424,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2> | |
| <div class="section" id="maintainers"> | ||
| <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2> | ||
| <p>This module is maintained by the OCA.</p> | ||
| <a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> | ||
| <a class="reference external image-reference" href="https://odoo-community.org"> | ||
| <img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /> | ||
| </a> | ||
| <p>OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use.</p> | ||
|
|
||
31 changes: 31 additions & 0 deletions
31
pos_product_quick_info/static/src/xml/Popups/ProductInfoPopup.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,31 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <templates xml:space="preserve"> | ||
| <!-- Extension of the ProductInfoPopup template --> | ||
| <t t-name="pos_product_quick_info.ProductInfoPopup" t-inherit="point_of_sale.ProductInfoPopup" t-inherit-mode="extension" owl="1"> | ||
|
|
||
| <!-- Location: immediately after each warehouse --> | ||
| <xpath expr="//div[@class='section-inventory-body']/table/t[@t-foreach='productInfo.warehouses']/tr" position="after"> | ||
| <!-- This code will be within the context of each warehouse. --> | ||
| <t t-if="warehouse.locations"> | ||
| <tr> | ||
| <td colspan="3" style="padding-left: 1rem; font-weight: bold;"> | ||
| <t t-esc="env._t('Locations:')"/> | ||
| </td> | ||
| </tr> | ||
| <t t-foreach="warehouse.locations" t-as="location" t-key="location.name"> | ||
| <tr> | ||
| <td style="padding-left: 2rem;"><span t-esc="location.name" class="table-name"/>:</td> | ||
| <td><t t-esc="location.available_quantity"/> <t t-esc="warehouse.uom"/> available,</td> | ||
| <td><t t-esc="location.forecasted_quantity"/> forecasted</td> | ||
| </tr> | ||
| </t> | ||
| </t> | ||
| </xpath> | ||
| <xpath expr="//div[@class='section-product-info-title']" position="after"> | ||
| <div t-if="props.product.description_sale" style="text-align: justify; padding: 0.5rem 1rem;"> | ||
| <t t-esc="props.product.description_sale"/> | ||
| </div> | ||
| </xpath> | ||
|
|
||
| </t> | ||
| </templates> |
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
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.
Uh oh!
There was an error while loading. Please reload this page.