Add do_try wizard.

This commit refs #16536
This commit is contained in:
Sergio Morillo 2020-12-23 18:23:50 +01:00
parent ab024dfd26
commit 26d34bd6de
10 changed files with 80 additions and 66 deletions

View File

@ -1,49 +1,44 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import Pool
from .load import (Load, LoadOrder, LoadOrderLine,
LoadUnitLoad, LoadUnitLoadOrder,
LoadUnitLoadData, Configuration, LoadSheet, CMR,
RoadTransportNote, LoadUnitLoadFailed, LoadOrderGrouping, LoadOrderLineUL)
from .unit_load import UnitLoad, UnitLoadLabel
from .sale import (Sale, SaleLine, CreateLoad, CreateLoadFromSale,
CreateLoadLineFromSale)
from .party import Party
from . import load
from . import unit_load
from . import sale
from . import party
from . import configuration
from . import stock
def register():
Pool.register(
UnitLoad,
Configuration,
Load,
LoadOrder,
LoadOrderLine,
LoadUnitLoadOrder,
LoadUnitLoadData,
LoadOrderLineUL,
Sale,
SaleLine,
CreateLoadFromSale,
CreateLoadLineFromSale,
LoadUnitLoadFailed,
unit_load.UnitLoad,
load.Configuration,
load.Load,
load.LoadOrder,
load.LoadOrderLine,
load.LoadUnitLoadOrder,
load.LoadUnitLoadData,
load.LoadOrderLineUL,
sale.Sale,
sale.SaleLine,
sale.CreateLoadFromSale,
sale.CreateLoadLineFromSale,
load.LoadUnitLoadFailed,
stock.Move,
module='carrier_load_ul', type_='model')
Pool.register(
LoadUnitLoad,
CreateLoad,
load.LoadUnitLoad,
sale.CreateLoad,
module='carrier_load_ul', type_='wizard')
Pool.register(
LoadSheet,
CMR,
RoadTransportNote,
UnitLoadLabel,
load.LoadSheet,
load.CMR,
load.RoadTransportNote,
unit_load.UnitLoadLabel,
module='carrier_load_ul', type_='report')
Pool.register(
Party,
LoadOrderGrouping,
party.Party,
load.LoadOrderGrouping,
configuration.Configuration,
configuration.ConfigurationLoad,
module='carrier_load_ul', type_='model',

59
load.py
View File

@ -83,7 +83,8 @@ class LoadOrder(metaclass=PoolMeta):
'run_try': {
'icon': 'tryton-forward',
'invisible': ~Eval('state').in_(['waiting', 'running']),
'depends': ['state']},
'depends': ['state']
},
})
cls._error_messages.update({
'cancel_ul': 'Cannot cancel load orders with loaded ULs',
@ -479,24 +480,18 @@ class LoadOrder(metaclass=PoolMeta):
failed_uls = []
for unit_load in unit_loads:
# check state
if unit_load.state != 'done':
self.raise_user_error('ul_state', unit_load.rec_name)
self.check_add_unit_load_state(unit_load)
# check it is not loaded yet
if unit_load.load_line:
self.raise_user_error('ul_loaded', unit_load.rec_name)
location = unit_load.location
# check it is in storage location
if location.type != 'storage':
if unit_load.location.type != 'storage':
self.raise_user_error('ul_location', unit_load.rec_name)
# check it is in warehouse
wh = location.warehouse
if not wh or wh.id != self.load.warehouse.id:
self.raise_user_error('ul_warehouse', (
unit_load.rec_name, self.load.warehouse.rec_name,
self.rec_name))
self.check_add_unit_load_warehouse(unit_load)
# check it is linked to origin lines
lines = self._get_lines_from_origin_uls(unit_load)
@ -533,6 +528,17 @@ class LoadOrder(metaclass=PoolMeta):
UL.save(unit_loads)
def check_add_unit_load_state(self, unit_load):
if unit_load.state != 'done':
self.raise_user_error('ul_state', unit_load.rec_name)
def check_add_unit_load_warehouse(self, unit_load):
wh = unit_load.location.warehouse
if not wh or wh.id != self.load.warehouse.id:
self.raise_user_error('ul_warehouse', (
unit_load.rec_name, self.load.warehouse.rec_name,
self.rec_name))
def _choose_matched_line(self, lines, values, unit_load):
line = None
for _line in lines:
@ -731,7 +737,7 @@ class LoadUnitLoad(Wizard):
'carrier_load_ul.load_uls_data_view_form', [
Button('Cancel', 'exit', 'tryton-cancel'),
Button('Unload ULs', 'unload_', 'tryton-undo'),
Button('Do', 'do_', 'tryton-ok', states={
Button('Do', 'pre_do', 'tryton-ok', states={
'readonly': Eval('ul_code') | Eval('uls_to_load'),
'invisible': (Eval('order_state') == 'done')}),
Button('Load', 'load_', 'tryton-add', default=True)])
@ -748,7 +754,8 @@ class LoadUnitLoad(Wizard):
force = StateTransition()
load_ = StateTransition()
unload_ = StateTransition()
do_ = StateTransition()
pre_do = StateTransition()
do_ = StateAction('carrier_load.wizard_load_order_do_try')
open_ = StateAction('carrier_load.act_load_order')
exit = StateTransition()
@ -834,14 +841,25 @@ class LoadUnitLoad(Wizard):
'failed_uls': [f.id for f in failed_uls]
}
def transition_do_(self):
pool = Pool()
Order = pool.get('carrier.load.order')
def transition_pre_do(self):
return 'do_'
def do_do_(self, action):
order, standalone = self._get_load_order()
data = {
'ids': [order.id],
'id': order.id,
'model': order.__name__,
}
return action, data
def transition_do_(self):
return 'exit'
def do_open_(self, action):
order, _ = self._get_load_order()
Order.do([order])
# TODO: print reports
return self.transition_exit()
action['views'].reverse()
return action, {'res_id': [order.id]}
def transition_exit(self):
if Transaction().context['active_model'] != 'carrier.load.order':
@ -891,11 +909,6 @@ class LoadUnitLoad(Wizard):
cls.raise_user_error('invalid_ul', code)
return uls
def do_open_(self, action):
order, _ = self._get_load_order()
action['views'].reverse()
return action, {'res_id': [order.id]}
class LoadSheet(metaclass=PoolMeta):
__name__ = 'carrier.load.sheet'

View File

@ -20,12 +20,14 @@ this repository contains the full copyright notices and license terms. -->
<field name="user" ref="res.user_admin"/>
<field name="group" ref="group_force_load"/>
</record>
<!-- Configuration -->
<record model="ir.ui.view" id="carrier_configuration_view_form">
<field name="model">carrier.configuration</field>
<field name="name">configuration_form</field>
<field name="inherit" ref="carrier_configuration.configuration_view_form"/>
</record>
<!-- Order -->
<record model="ir.ui.view" id="load_order_view_form">
<field name="model">carrier.load.order</field>
@ -55,6 +57,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="button" ref="unit_load_run_try_button"/>
<field name="group" ref="carrier_configuration.group_carrier"/>
</record>
<!-- Order line -->
<record model="ir.ui.view" id="load_order_line_view_form">
<field name="model">carrier.load.order.line</field>
@ -66,12 +69,14 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">load_order_line_list</field>
<field name="inherit" ref="carrier_load.load_order_line_view_tree"/>
</record>
<!-- Wizard load UL -->
<record model="ir.action.wizard" id="wizard_load_ul">
<field name="name">Start loading</field>
<field name="wiz_name">carrier.load_uls</field>
<field name="model">carrier.load.order</field>
</record>
<!-- Wizard load UL global -->
<record model="ir.action.wizard" id="wizard_global_load_ul">
<field name="name">Start loading</field>
@ -79,6 +84,7 @@ this repository contains the full copyright notices and license terms. -->
</record>
<menuitem id="menu_start_loading" name="Start loading" sequence="90"
parent="carrier.menu_carrier" action="wizard_global_load_ul"/>
<!-- Wizard state views -->
<record model="ir.ui.view" id="load_uls_order_view_form">
<field name="model">carrier.load_uls.order</field>
@ -111,6 +117,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<!-- Load report -->
<record model="ir.action.report" id="carrier_load.report_load_sheet">
<field name="active" eval="False"/>
@ -142,6 +149,5 @@ this repository contains the full copyright notices and license terms. -->
<field name="action" ref="wizard_force_load_ul"/>
<field name="group" ref="group_force_unload"/>
</record>
</data>
</tryton>

View File

@ -450,7 +450,7 @@ msgctxt "wizard_button:carrier.load.create_wizard,sale_data,load_:"
msgid "OK"
msgstr "Aceptar"
msgctxt "wizard_button:carrier.load_uls,data,do_:"
msgctxt "wizard_button:carrier.load_uls,data,pre_do:"
msgid "Do"
msgstr "Finalizar"

View File

@ -310,13 +310,13 @@ Unload UL::
Finish loading::
>>> start_load = Wizard('carrier.load_uls', [order])
>>> start_load.execute('do_') # doctest: +IGNORE_EXCEPTION_DETAIL
>>> start_load.execute('pre_do') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserWarning: ('UserWarning', ('pending_uls_1', 'You have loaded less ULs (1) than expected (2).', ''))
>>> Model.get('res.user.warning')(user=config.user,
... name='pending_uls_1', always=True).save()
>>> start_load.execute('do_')
>>> start_load.execute('pre_do')
>>> order.reload()
>>> len(order.unit_loads)
1

View File

@ -332,7 +332,7 @@ Finish loading::
>>> start_load = Wizard('carrier.load_uls', [load_order])
>>> Model.get('res.user.warning')(user=config.user,
... name='pending_uls_1', always=True).save()
>>> start_load.execute('do_')
>>> start_load.execute('pre_do')
>>> load_order.reload()
>>> len(load_order.unit_loads)
3
@ -381,7 +381,7 @@ Load the other UL of sale::
>>> start_load.execute('load_')
>>> start_load.form.ul_code = uls[4].code
>>> start_load.execute('load_')
>>> start_load.execute('do_')
>>> start_load.execute('pre_do')
>>> sale.reload()
>>> len(sale.shipments)
2

View File

@ -310,13 +310,13 @@ Unload UL::
Finish loading::
>>> start_load = Wizard('carrier.load_uls', [order])
>>> start_load.execute('do_') # doctest: +IGNORE_EXCEPTION_DETAIL
>>> start_load.execute('pre_do') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserWarning: ('UserWarning', ('pending_uls_1', 'You have loaded less ULs (1) than expected (2).', ''))
>>> Model.get('res.user.warning')(user=config.user,
... name='pending_uls_1', always=True).save()
>>> start_load.execute('do_')
>>> start_load.execute('pre_do')
>>> order.reload()
>>> len(order.unit_loads)
1

View File

@ -312,13 +312,13 @@ Unload UL::
Finish loading::
>>> start_load = Wizard('carrier.load_uls', [order])
>>> start_load.execute('do_') # doctest: +IGNORE_EXCEPTION_DETAIL
>>> start_load.execute('pre_do') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserWarning: ('UserWarning', ('pending_uls_1', 'You have loaded less ULs (1) than expected (2).', ''))
>>> Model.get('res.user.warning')(user=config.user,
... name='pending_uls_1', always=True).save()
>>> start_load.execute('do_')
>>> start_load.execute('pre_do')
>>> order.reload()
>>> len(order.unit_loads)
1

View File

@ -150,7 +150,7 @@ Load UL into internal order::
True
>>> start_load.form.ul_code = ul2.code
>>> start_load.execute('load_')
>>> start_load.execute('do_')
>>> start_load.execute('pre_do')
>>> ul.reload()
>>> ul.load_order == load_order
True
@ -199,7 +199,7 @@ Create sale and load UL::
True
>>> ul.load_line == load_order2.lines[0]
True
>>> start_load.execute('do_')
>>> start_load.execute('pre_do')
>>> load_order2.reload()
>>> ul.reload()
>>> ul.load_order == load_order2

View File

@ -16,7 +16,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="outgoing_moves" colspan="4"/>
</page>
</xpath>
<xpath expr="/form/group[@id='state_buttons']/group[@id='buttons']/button[@name='do']"
<xpath expr="/form/group[@id='state_buttons']/group[@id='buttons']/button[@name='do_try']"
position="before">
<button name="run_try"/>
</xpath>