mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_move_location: Improve UI and add hooks
The sql query is replaced by the read_group method from the orm. This allows the use of odoo domain and the definition of a new method that can be overriden to get the domain to retrieve the quants. Extract the initialization logic for the stock_move_location_line_ids field into a dedicated method to allow to be called wy others addons. Improve the wizard form: * Toggle fields are now properly displayed * Add a placeholder group to be used by specialized addon to add additional filters
This commit is contained in:
@@ -62,8 +62,8 @@ If you want to transfer a full quant:
|
||||
- Select the quantities which you want move to another location
|
||||
|
||||
If you go to the Inventory Dashboard you can see the button "Move from
|
||||
location" in each of the picking types (only applicable to internal
|
||||
transfers). Press it and you will be directed to the wizard.
|
||||
location" in each of the picking types (only applicable to internal and
|
||||
outgoing transfers). Press it and you will be directed to the wizard.
|
||||
|
||||
|image1|
|
||||
|
||||
@@ -143,6 +143,8 @@ Contributors
|
||||
|
||||
- Aung Ko Ko Lin
|
||||
|
||||
- Laurent Mignon <laurent.mignon@acsone.eu>
|
||||
|
||||
Maintainers
|
||||
-----------
|
||||
|
||||
|
||||
@@ -13,3 +13,4 @@
|
||||
- Abraham Anes \<<abraham@studio73.es>\>
|
||||
- Quartile \<<https://www.quartile.co>\>
|
||||
- Aung Ko Ko Lin
|
||||
- Laurent Mignon \<<laurent.mignon@acsone.eu>\>
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
: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 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
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.option {
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
span.problematic, pre.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
@@ -411,8 +412,8 @@ opened.</li>
|
||||
<li>Select the quantities which you want move to another location</li>
|
||||
</ul>
|
||||
<p>If you go to the Inventory Dashboard you can see the button “Move from
|
||||
location” in each of the picking types (only applicable to internal
|
||||
transfers). Press it and you will be directed to the wizard.</p>
|
||||
location” in each of the picking types (only applicable to internal and
|
||||
outgoing transfers). Press it and you will be directed to the wizard.</p>
|
||||
<p><img alt="image1" src="https://user-images.githubusercontent.com/147538094/281480833-208ea309-0bad-43e7-bd6f-8384520afe00.png" /></p>
|
||||
<p>To enable this option, check “Show Move On Hand Stock” in the Picking
|
||||
Type configuration.</p>
|
||||
@@ -482,12 +483,15 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
|
||||
<li>Aung Ko Ko Lin</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Laurent Mignon <<a class="reference external" href="mailto:laurent.mignon@acsone.eu">laurent.mignon@acsone.eu</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#toc-entry-7">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>
|
||||
|
||||
@@ -303,25 +303,32 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
)
|
||||
return action
|
||||
|
||||
def _get_quants_domain(self):
|
||||
return [("location_id", "=", self.origin_location_id.id)]
|
||||
|
||||
def _get_group_quants(self):
|
||||
location_id = self.origin_location_id
|
||||
# Using sql as search_group doesn't support aggregation functions
|
||||
# leading to overhead in queries to DB
|
||||
query = """
|
||||
SELECT product_id, lot_id, package_id, owner_id, SUM(quantity) AS quantity,
|
||||
SUM(reserved_quantity) AS reserved_quantity
|
||||
FROM stock_quant
|
||||
WHERE location_id = %s
|
||||
GROUP BY product_id, lot_id, package_id, owner_id
|
||||
"""
|
||||
self.env.cr.execute(query, (location_id.id,))
|
||||
return self.env.cr.dictfetchall()
|
||||
domain = self._get_quants_domain()
|
||||
result = self.env["stock.quant"].read_group(
|
||||
domain=domain,
|
||||
fields=[
|
||||
"product_id",
|
||||
"lot_id",
|
||||
"package_id",
|
||||
"owner_id",
|
||||
"quantity:sum",
|
||||
"reserved_quantity:sum",
|
||||
],
|
||||
groupby=["product_id", "lot_id", "package_id", "owner_id"],
|
||||
orderby="id",
|
||||
lazy=False,
|
||||
)
|
||||
return result
|
||||
|
||||
def _get_stock_move_location_lines_values(self):
|
||||
product_obj = self.env["product.product"]
|
||||
product_data = []
|
||||
for group in self._get_group_quants():
|
||||
product = product_obj.browse(group.get("product_id")).exists()
|
||||
product = product_obj.browse(group["product_id"][0]).exists()
|
||||
# Apply the putaway strategy
|
||||
location_dest_id = (
|
||||
self.apply_putaway_strategy
|
||||
@@ -337,15 +344,33 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
"origin_location_id": self.origin_location_id.id,
|
||||
"destination_location_id": location_dest_id,
|
||||
# cursor returns None instead of False
|
||||
"lot_id": group.get("lot_id") or False,
|
||||
"package_id": group.get("package_id") or False,
|
||||
"owner_id": group.get("owner_id") or False,
|
||||
"lot_id": group["lot_id"][0] if group.get("lot_id") else False,
|
||||
"package_id": group["package_id"][0]
|
||||
if group.get("package_id")
|
||||
else False,
|
||||
"owner_id": group["owner_id"][0]
|
||||
if group.get("owner_id")
|
||||
else False,
|
||||
"product_uom_id": product.uom_id.id,
|
||||
"custom": False,
|
||||
}
|
||||
)
|
||||
return product_data
|
||||
|
||||
def _reset_stock_move_location_lines(self):
|
||||
lines = []
|
||||
line_model = self.env["wiz.stock.move.location.line"]
|
||||
for line_val in self._get_stock_move_location_lines_values():
|
||||
if line_val.get("max_quantity") <= 0:
|
||||
continue
|
||||
line = line_model.create(line_val)
|
||||
line.max_quantity = line.get_max_quantity()
|
||||
line.reserved_quantity = line.reserved_quantity
|
||||
lines.append(line)
|
||||
self.update(
|
||||
{"stock_move_location_line_ids": [(6, 0, [line.id for line in lines])]}
|
||||
)
|
||||
|
||||
@api.onchange("origin_location_id")
|
||||
def onchange_origin_location(self):
|
||||
# Get origin_location_disable context key to prevent load all origin
|
||||
@@ -355,18 +380,7 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
not self.env.context.get("origin_location_disable")
|
||||
and self.origin_location_id
|
||||
):
|
||||
lines = []
|
||||
line_model = self.env["wiz.stock.move.location.line"]
|
||||
for line_val in self._get_stock_move_location_lines_values():
|
||||
if line_val.get("max_quantity") <= 0:
|
||||
continue
|
||||
line = line_model.create(line_val)
|
||||
line.max_quantity = line.get_max_quantity()
|
||||
line.reserved_quantity = line.reserved_quantity
|
||||
lines.append(line)
|
||||
self.update(
|
||||
{"stock_move_location_line_ids": [(6, 0, [line.id for line in lines])]}
|
||||
)
|
||||
self._reset_stock_move_location_lines()
|
||||
|
||||
def clear_lines(self):
|
||||
self._clear_lines()
|
||||
|
||||
@@ -10,18 +10,15 @@
|
||||
<form>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box" />
|
||||
<div>
|
||||
<label for="edit_locations">
|
||||
Edit Locations
|
||||
</label>
|
||||
<group name="options">
|
||||
<field name="edit_locations" widget="boolean_toggle" />
|
||||
</div>
|
||||
<div groups="stock.group_stock_multi_locations">
|
||||
<label for="apply_putaway_strategy">
|
||||
Apply putaway strategy for moving products
|
||||
</label>
|
||||
<field name="apply_putaway_strategy" widget="boolean_toggle" />
|
||||
</div>
|
||||
<field
|
||||
name="apply_putaway_strategy"
|
||||
string="Apply putaway strategy for moving products"
|
||||
widget="boolean_toggle"
|
||||
groups="stock.group_stock_multi_locations"
|
||||
/>
|
||||
</group>
|
||||
<group name="picking_type">
|
||||
<field name="picking_type_id" />
|
||||
</group>
|
||||
@@ -37,6 +34,8 @@
|
||||
attrs="{'readonly': [('destination_location_disable', '=', True)]}"
|
||||
/>
|
||||
</group>
|
||||
<group name="filters">
|
||||
</group>
|
||||
<group name="lines">
|
||||
<field
|
||||
name="stock_move_location_line_ids"
|
||||
|
||||
Reference in New Issue
Block a user