Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pos_product_quick_info/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"pos_product_quick_info/static/src/css/pos.css",
"pos_product_quick_info/static/src/js/Screens/ProductScreen/ProductItem.js",
"pos_product_quick_info/static/src/xml/Screens/ProductScreen/ProductItem.xml",
"pos_product_quick_info/static/src/xml/Popups/ProductInfoPopup.xml",
],
},
"installable": True,
Expand Down
43 changes: 42 additions & 1 deletion pos_product_quick_info/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ msgstr "Ajustes"

#. module: pos_product_quick_info
#: model:ir.model.fields,field_description:pos_product_quick_info.field_pos_config__display_quick_product_info
#: model:ir.model.fields,field_description:pos_product_quick_info.field_product_product__display_quick_product_info
#: model:ir.model.fields,field_description:pos_product_quick_info.field_res_config_settings__pos_display_quick_product_info
msgid "Display Quick Product Info"
msgstr "Mostrar información de producto"
Expand All @@ -32,14 +33,54 @@ msgstr "Mostrar información de producto"
msgid "Display product info by one click"
msgstr "Mostrar información de producto en un clic"

#. module: pos_product_quick_info
#: model:ir.model.fields,field_description:pos_product_quick_info.field_pos_config__display_product_locations
#: model:ir.model.fields,field_description:pos_product_quick_info.field_res_config_settings__pos_display_product_locations
msgid "Display product locations in product info"
msgstr "Mostrar la ubicación de los productos en la información del producto"

#. module: pos_product_quick_info
#. odoo-javascript
#: code:addons/pos_product_quick_info/static/src/xml/Screens/ProductScreen/ProductItem.xml:0
#: code:addons/pos_product_quick_info/static/src/xml/Screens/ProductScreen/ProductItem.xml:0
#, python-format
msgid "Info"
msgstr "Información"

#. module: pos_product_quick_info
#. odoo-javascript
#: code:addons/pos_product_quick_info/static/src/xml/Popups/ProductInfoPopup.xml:0
#, python-format
msgid "Locations:"
msgstr "Ubicaciones:"

#. module: pos_product_quick_info
#: model:ir.model,name:pos_product_quick_info.model_pos_config
msgid "Point of Sale Configuration"
msgstr "Configuración del punto de venta"
msgstr "Configuración del Punto de Venta"

#. module: pos_product_quick_info
#: model:ir.model,name:pos_product_quick_info.model_product_product
msgid "Product Variant"
msgstr "Variante de producto"

#. module: pos_product_quick_info
#: model_terms:ir.ui.view,arch_db:pos_product_quick_info.res_config_settings_view_form
msgid "Show locations per warehouse in product info popup"
msgstr ""
"Mostrar ubicaciones por almacén en la ventana emergente de información del "
"producto"

#. module: pos_product_quick_info
#. odoo-javascript
#: code:addons/pos_product_quick_info/static/src/xml/Popups/ProductInfoPopup.xml:0
#, python-format
msgid "available,"
msgstr "disponible,"

#. module: pos_product_quick_info
#. odoo-javascript
#: code:addons/pos_product_quick_info/static/src/xml/Popups/ProductInfoPopup.xml:0
#, python-format
msgid "forecasted"
msgstr "previsto"
1 change: 1 addition & 0 deletions pos_product_quick_info/models/__init__.py
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
4 changes: 4 additions & 0 deletions pos_product_quick_info/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ class PosConfig(models.Model):
_inherit = "pos.config"

display_quick_product_info = fields.Boolean(default=True)
display_product_locations = fields.Boolean(
string="Display product locations in product info",
default=True
)
143 changes: 143 additions & 0 deletions pos_product_quick_info/models/product_product.py
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

Choose a reason for hiding this comment

The 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:
https://github.com/odoo/odoo/blob/85073d10a9f4b5a74d31adcba815651d6f217dbf/addons/stock/models/product.py#L136


# 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
4 changes: 4 additions & 0 deletions pos_product_quick_info/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ class ResConfigSettings(models.TransientModel):
pos_display_quick_product_info = fields.Boolean(
related="pos_config_id.display_quick_product_info", readonly=False
)
pos_display_product_locations = fields.Boolean(
related="pos_config_id.display_product_locations",
readonly=False
)
11 changes: 7 additions & 4 deletions pos_product_quick_info/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -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>
Expand Down
31 changes: 31 additions & 0 deletions pos_product_quick_info/static/src/xml/Popups/ProductInfoPopup.xml
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>
12 changes: 12 additions & 0 deletions pos_product_quick_info/views/res_config_settings_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box"
attrs="{'invisible': [('pos_display_quick_product_info', '=', False)]}">
<div class="o_setting_left_pane">
<field name="pos_display_product_locations"/>
</div>
<div class="o_setting_right_pane">
<label for="pos_display_product_locations"/>
<div class="text-muted">
Show locations per warehouse in product info popup
</div>
</div>
</div>
</xpath>
</field>
</record>
Expand Down