Skip to content

Commit

Permalink
[MIG] stock_lot_on_hand_first: migrate to V17
Browse files Browse the repository at this point in the history
  • Loading branch information
astirpe committed Oct 14, 2024
1 parent e161bde commit 254e49d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion stock_lot_on_hand_first/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Stock Lot On Hand First",
"summary": "Allows to display lots on hand first in M2o fields",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"development_status": "Alpha",
"category": "Inventory/Inventory",
"website": "https://github.com/OCA/stock-logistics-workflow",
Expand Down
26 changes: 12 additions & 14 deletions stock_lot_on_hand_first/models/stock_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,36 @@ class StockLot(models.Model):
_inherit = "stock.lot"

@api.model
def _name_search(
self, name="", args=None, operator="ilike", limit=80, name_get_uid=None
):
def _name_search(self, name, domain=None, operator="ilike", limit=None, order=None):
"""Move lots without a qty on hand at the end of the list"""

if self.env.context.get("name_search_qty_on_hand_first"):
args = list(args or [])
domain = list(domain or [])

with_quantity_domain = AND([args, [("product_qty", ">", 0)]])
with_quantity_domain = AND([domain, [("product_qty", ">", 0)]])
with_quantity_count = self.env["stock.lot"].search_count(
with_quantity_domain
)

if with_quantity_count >= limit:
args = with_quantity_domain
domain = with_quantity_domain

Check warning on line 23 in stock_lot_on_hand_first/models/stock_lot.py

View check run for this annotation

Codecov / codecov/patch

stock_lot_on_hand_first/models/stock_lot.py#L23

Added line #L23 was not covered by tests
else:
with_quantity_ids = super()._name_search(
name=name,
args=with_quantity_domain,
domain=with_quantity_domain,
operator=operator,
limit=limit,
name_get_uid=name_get_uid,
order=order,
)
without_quantity_ids = super()._name_search(
name=name,
args=AND([args, [("product_qty", "=", 0)]]),
domain=AND([domain, [("product_qty", "=", 0)]]),
operator=operator,
limit=limit - with_quantity_count,
name_get_uid=name_get_uid,
order=order,
)
# _name_search is supposed to return a odoo.osv.query.Query object
# that will be evaluated as a list of ids when used in the browse function.
# _name_search is supposed to return a odoo.osv.query.Query object that
# will be evaluated as a list of ids when used in the browse function.
# Since we cannot merge the Query objects to respect the intended order
# in which we want to display the results, we return the list of ids
# that will be used by browse in the name_search implementation.
Expand All @@ -50,8 +48,8 @@ def _name_search(

return super()._name_search(

Check warning on line 49 in stock_lot_on_hand_first/models/stock_lot.py

View check run for this annotation

Codecov / codecov/patch

stock_lot_on_hand_first/models/stock_lot.py#L49

Added line #L49 was not covered by tests
name=name,
args=args,
domain=domain,
operator=operator,
limit=limit,
name_get_uid=name_get_uid,
order=order,
)
4 changes: 2 additions & 2 deletions stock_lot_on_hand_first/views/stock_picking_type.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="ir.ui.view" id="view_picking_type_form_inherit">
<record id="view_picking_type_form_inherit" model="ir.ui.view">
<field name="name">Operation Types</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_form" />
<field name="arch" type="xml">
<field name="use_existing_lots" position="after">
<field
name="display_lots_on_hand_first"
attrs="{'invisible': [('use_existing_lots', '!=', True)]}"
invisible="not use_existing_lots"
/>
</field>
</field>
Expand Down

0 comments on commit 254e49d

Please sign in to comment.