Skip to content

Commit

Permalink
[MIG] sale_order_lot_selection_ux: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cem-adhoc committed Jul 23, 2024
1 parent 868f369 commit 6f119ff
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions sale_order_lot_selection_ux/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
Sale Order Lot Selection UX
===========================

This extend functionally from the "Sale Order Lot Selection" module.
This module makes it possible to select lots with at least one unit available.
This extends the functionality of the "Sales Order Batch Selection" module.
This module allows you to select lots with at least one unit available and allows you to view their available stock.

Installation
============
Expand Down
4 changes: 2 additions & 2 deletions sale_order_lot_selection_ux/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Sale Order Lot Selection UX',
'version': "16.0.1.0.0",
'version': "17.0.1.0.0",
'category': 'Sale',
'sequence': 14,
'author': 'ADHOC SA',
Expand All @@ -32,7 +32,7 @@
'views/sale_order_views.xml',
'views/stock_production_lot.xml',
],
'installable': False,
'installable': True,
'auto_install': False,
'application': False,
}
10 changes: 5 additions & 5 deletions sale_order_lot_selection_ux/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def _compute_available_lot_ids(self):
if (rec.product_id.tracking in ['serial', 'lot']
and rec.order_id.warehouse_id):
location = rec.order_id.warehouse_id.lot_stock_id
quants = self.env['stock.quant'].read_group([
quants = self.env['stock.quant']._read_group([
('product_id', '=', rec.product_id.id),
('location_id', 'child_of', location.id),
('quantity', '>', 0),
('lot_id', '!=', False),
], ['lot_id', 'reserved_quantity', 'quantity'], 'lot_id')
],['lot_id'], ['reserved_quantity:sum', 'quantity:sum'] )
available_lot_ids = [
quant['lot_id'][0] for quant in quants
if quant['reserved_quantity'] < quant['quantity']]
quant[0].id for quant in quants
if quant[1] < quant[2]]
rec.available_lot_ids = available_lot_ids
else:
rec.available_lot_ids = False
rec.available_lot_ids = False
12 changes: 5 additions & 7 deletions sale_order_lot_selection_ux/models/stock_production_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
class ProductionLot(models.Model):
_inherit = 'stock.lot'

def name_get(self):
if not self._context.get('from_sale_line', False):
return super().name_get()
def _compute_display_name(self):
if not self._context.get('from_sale_line', False) or not self._context.get('warehouse_id', False) :
return super()._compute_display_name()
location = self.env['stock.warehouse'].browse(self._context.get('warehouse_id', [])).lot_stock_id
result = []
for rec in self:
quants = rec.quant_ids.filtered(lambda x : x.location_id == location)
quants = rec.quant_ids.filtered(lambda x : x.location_id.location_id == location)
qty = quants and sum(quants.mapped(lambda x: x.quantity - x.reserved_quantity)) or 0.0
name = rec.name + " (%s %s) " % (qty, quants and quants[0].product_uom_id.name or ' ')
result.append((rec.id, name))
return result
rec.display_name = name
4 changes: 2 additions & 2 deletions sale_order_lot_selection_ux/views/sale_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<field name="inherit_id" ref="sale_order_lot_selection.view_order_tree_lot"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='product_id']" position="after">
<field name="available_lot_ids" invisible="1"/>
<field name="available_lot_ids" column_invisible="1"/>
</xpath>
<xpath expr="//field[@name='order_line']/form/group/group/field[@name='product_id']" position="after">
<field name="available_lot_ids" invisible="1"/>
<field name="available_lot_ids" column_invisible="1"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='lot_id']" position="attributes">
<attribute name="domain">[('id', 'in', available_lot_ids)]</attribute>
Expand Down

0 comments on commit 6f119ff

Please sign in to comment.