Improve uls by location query.

This commit refs #19717
This commit is contained in:
Sergio Morillo 2021-12-16 22:00:34 +01:00
parent 095e141efb
commit e2b8ef7d42
7 changed files with 39 additions and 139 deletions

View File

@ -7,8 +7,7 @@ from .unit_load import (UnitLoad, UnitLoadMove, MoveUnitLoad,
DropUnitLoadData, DropUnitLoadFailed, DropUnitLoadFailedProduct,
BatchDropUnitLoad, BatchDropUnitLoadData, BatchDropUnitLoadConfirm,
DropUnitLoadUL, DropUnitLoadEndDate, CaseLabel)
from .stock import (Move, UnitLoadsByLocations,
UnitLoadsByLocationsStart, Move2)
from .stock import Move, Move2
from .shipment import (ShipmentOut, ShipmentInternal, ShipmentOutReturn,
ShipmentInReturn)
from .res import User
@ -31,7 +30,6 @@ def register():
DropUnitLoadUL,
DropUnitLoadFailed,
DropUnitLoadFailedProduct,
UnitLoadsByLocationsStart,
ShipmentOut,
ShipmentInternal,
ShipmentOutReturn,
@ -43,7 +41,6 @@ def register():
Pool.register(
MoveUnitLoad,
DropUnitLoad,
UnitLoadsByLocations,
BatchDropUnitLoad,
module='stock_unit_load', type_='wizard')
Pool.register(

View File

@ -370,24 +370,6 @@ msgctxt "field:stock.unit_load.move,write_uid:"
msgid "Write User"
msgstr "Usuario modificación"
msgctxt "field:stock.unit_loads_by_locations.start,forecast_date:"
msgid "At Date"
msgstr "A fecha"
msgctxt "field:stock.unit_loads_by_locations.start,id:"
msgid "ID"
msgstr "Identificador"
msgctxt "help:stock.unit_loads_by_locations.start,forecast_date:"
msgid ""
"Allow to compute expected stock quantities for this date.\n"
"* An empty value is an infinite date in the future.\n"
"* A date in the past will provide historical values."
msgstr ""
"Permite calcular las cantidades previstas de stock para esta fecha.\n"
"* Un valor vacío es un fecha infinita en el futuro.\n"
"* Una fecha en el pasado proporcionará valores históricos."
msgctxt "model:ir.action,name:act_uls_by_locations"
msgid "Unit loads"
msgstr "Unidades de carga"
@ -420,10 +402,6 @@ msgctxt "model:ir.action,name:wizard_global_drop_unit_load"
msgid "Drop UL"
msgstr "Volcar UdC"
msgctxt "model:ir.action,name:wizard_uls_by_locations"
msgid "ULs by Locations"
msgstr "UdCs por ubicación"
msgctxt "model:ir.action.act_window.domain,name:act_unit_load_domain_all"
msgid "All"
msgstr "Todos"
@ -506,10 +484,6 @@ msgctxt "model:stock.unit_load.move,name:"
msgid "Unit load movement"
msgstr "Movimiento UdC"
msgctxt "model:stock.unit_loads_by_locations.start,name:"
msgid "Unit loads by Locations"
msgstr "Unidades de carga por ubicación"
msgctxt "selection:stock.unit_load,state:"
msgid "Assigned"
msgstr "Reservado"
@ -626,18 +600,6 @@ msgctxt "wizard_button:stock.unit_load.do_move,start,move_:"
msgid "OK"
msgstr "Aceptar"
msgctxt "wizard_button:stock.unit_loads_by_locations,start,end:"
msgid "Cancel"
msgstr "Cancelar"
msgctxt "wizard_button:stock.unit_loads_by_locations,start,open:"
msgid "Open"
msgstr "Abrir"
msgctxt "view:stock.unit_loads_by_locations.start:"
msgid "Unit loads by Locations"
msgstr "Unidades de carga por ubicación"
msgctxt "field:stock.shipment.out,unit_loads:"
msgid "Unit loads"
msgstr "Unidades de carga"
@ -944,4 +906,8 @@ msgstr "Si se marca la fecha fin de volcado de una UdC se propondrá."
msgctxt "view:stock.configuration:"
msgid "Unit Load"
msgstr "Unidad de carga"
msgstr "Unidad de carga"
msgctxt "view:stock.unit_load:"
msgid "Available today"
msgstr "Disponible hoy"

View File

@ -1,19 +1,13 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from functools import wraps
import datetime
from trytond.pool import PoolMeta, Pool
from trytond.model import fields, ModelView, Workflow
from trytond.pyson import PYSONEncoder, Date, Bool
from trytond.transaction import Transaction
from trytond.wizard import Wizard, StateView, Button, StateAction
from trytond.model import fields, Workflow
from trytond.pyson import Bool
from trytond.exceptions import UserError
from trytond.i18n import gettext
from itertools import groupby
__all__ = ['Move', 'UnitLoadsByLocationsStart',
'UnitLoadsByLocations', 'Move2']
def set_unit_load_shipment(func):
@wraps(func)
@ -116,59 +110,6 @@ class Move(metaclass=PoolMeta):
return moves
class UnitLoadsByLocationsStart(ModelView):
"""Unit loads by Locations"""
__name__ = 'stock.unit_loads_by_locations.start'
forecast_date = fields.Date(
'At Date', help=('Allow to compute expected '
'stock quantities for this date.\n'
'* An empty value is an infinite date in the future.\n'
'* A date in the past will provide historical values.'))
@staticmethod
def default_forecast_date():
Date_ = Pool().get('ir.date')
return Date_.today()
class UnitLoadsByLocations(Wizard):
"""Unit loads by Locations"""
__name__ = 'stock.unit_loads_by_locations'
start = StateView('stock.unit_loads_by_locations.start',
'stock_unit_load.uls_by_locations_start_view_form',
[Button('Cancel', 'end', 'tryton-cancel'),
Button('Open', 'open', 'tryton-ok', True)])
open = StateAction('stock_unit_load.act_uls_by_locations')
def do_open(self, action):
pool = Pool()
Location = pool.get('stock.location')
Lang = pool.get('ir.lang')
context = {}
context['locations'] = Transaction().context.get('active_ids')
date = self.start.forecast_date or datetime.date.max
context['stock_date_end'] = Date(date.year, date.month, date.day)
action['pyson_context'] = PYSONEncoder().encode(context)
locations = Location.browse(context['locations'])
for code in [Transaction().language, 'en_US']:
langs = Lang.search([
('code', '=', code),
])
if langs:
break
lang = langs[0]
date = lang.strftime(date)
action['name'] += ' - (%s) @ %s' % (
','.join(l.name for l in locations), date)
return action, {}
class Move2(metaclass=PoolMeta):
__name__ = 'stock.move'

View File

@ -13,40 +13,36 @@
<field name="inherit" ref="stock.move_view_tree"/>
<field name="name">move_tree</field>
</record>
<!-- ULs by locations wizard -->
<record model="ir.action.wizard" id="wizard_uls_by_locations">
<field name="name">ULs by Locations</field>
<field name="wiz_name">stock.unit_loads_by_locations</field>
<field name="model">stock.location</field>
</record>
<record model="ir.action.keyword"
id="act_uls_by_locations_keyword1">
<field name="keyword">form_relate</field>
<field name="model">stock.location,-1</field>
<field name="action" ref="wizard_uls_by_locations"/>
</record>
<!-- ULs by locations start -->
<record model="ir.ui.view" id="uls_by_locations_start_view_form">
<field name="model">stock.unit_loads_by_locations.start</field>
<field name="type">form</field>
<field name="name">uls_by_locations_start_form</field>
</record>
<!-- action -->
<!-- ULs by location -->
<record model="ir.action.act_window" id="act_uls_by_locations">
<field name="name">Unit loads</field>
<field name="res_model">stock.unit_load</field>
<field name="domain" eval="[('quantity', '!=', 0.0)]" pyson="1"/>
<field name="context" eval="{'locations': Eval('active_ids')}"
pyson="1"/>
<field name="domain"
eval="[('quantity', '>', 0.0)]"
pyson="1"/>
<field name="context_model">stock.products_by_locations.context</field>
</record>
<record model="ir.action.act_window.view" id="act_unit_load_qty_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="unit_load_view_tree_qty"/>
<field name="act_window" ref="act_uls_by_locations"/>
</record>
<record model="ir.action.act_window.view" id="act_unit_load_qty_view2">
<field name="sequence" eval="20"/>
<field name="view" ref="unit_load_view_form"/>
<field name="act_window" ref="act_uls_by_locations"/>
<record model="ir.action.keyword"
id="act_uls_by_locations_keyword1">
<field name="keyword">tree_open</field>
<field name="model">stock.location,-1</field>
<field name="action" ref="act_uls_by_locations"/>
</record>
<record model="ir.action.keyword"
id="act_uls_by_locations_keyword2">
<field name="keyword">form_relate</field>
<field name="model">stock.location,-1</field>
<field name="action" ref="act_uls_by_locations"/>
</record>
<!-- Buttons -->
<record model="ir.model.button" id="unit_load_move_try_button">
<field name="name">move_try</field>

View File

@ -547,7 +547,10 @@ class UnitLoad(ModelSQL, ModelView):
uls = dict.fromkeys(list(map(int, records)), 0)
ul_products = {r.id: r.product.id for r in records}
quantities = cls._compute_quantities(records, location_ids)
with_childs = Transaction().context.get(
'with_childs', len(location_ids) == 1)
quantities = cls._compute_quantities(records, location_ids,
with_childs=with_childs)
if wh_to_add:
for wh, storage in wh_to_add.items():
@ -629,10 +632,12 @@ class UnitLoad(ModelSQL, ModelView):
location_ids, _, _ = cls._skip_warehouse_in_compute_quantities(
location_ids)
with_childs = Transaction().context.get(
'with_childs', len(location_ids) == 1)
with Transaction().set_context(cls._quantity_context(name)):
grouping = ('product', 'unit_load',)
query = Move.compute_quantities_query(location_ids,
with_childs=True,
with_childs=with_childs,
grouping=grouping,
grouping_filter=None)
@ -1081,8 +1086,9 @@ class UnitLoad(ModelSQL, ModelView):
if not record.dropped:
dropped_qty = record._get_dropped_quantity()
if dropped_qty:
dropped_cases = round((dropped_qty / record.quantity
) * record.cases_quantity, record.cases_digits)
dropped_cases = round(
(dropped_qty / record.internal_quantity
) * record.cases_quantity, record.cases_digits)
res[record.id] -= dropped_cases
else:
res[record.id] = 0.0

View File

@ -1,7 +0,0 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<form>
<label name="forecast_date"/>
<field name="forecast_date"/>
</form>

View File

@ -9,4 +9,5 @@
<field name="cases_quantity"/>
<field name="uom"/>
<field name="state"/>
<field name="available" string="Available today"/>
</tree>