New user group to allow do load order with pending quantity.

This commit refs #25529
This commit is contained in:
ramon.vidal 2023-01-20 10:23:06 +01:00 committed by Sergio Morillo
parent e7e8b8ecec
commit 992af4b969
4 changed files with 134 additions and 14 deletions

52
load.py
View File

@ -437,10 +437,26 @@ class LoadOrder(metaclass=PoolMeta):
@classmethod
def _check_loaded_quantity(cls, records):
pool = Pool()
Warning = pool.get('res.user.warning')
Configuration = pool.get('carrier.configuration')
ModelData = pool.get('ir.model.data')
User = pool.get('res.user')
Group = pool.get('res.group')
Warning = pool.get('res.user.warning')
conf = Configuration(1)
def in_group():
group = Group(ModelData.get_id('carrier_load_ul',
'group_do_load_pending_quantity'))
transaction = Transaction()
user_id = transaction.user
if user_id == 0:
user_id = transaction.context.get('user', user_id)
if user_id == 0:
return True
user = User(user_id)
return group in user.groups
for record in records:
if not record.unit_loads:
raise UserError(gettext(
@ -448,20 +464,32 @@ class LoadOrder(metaclass=PoolMeta):
order=record.rec_name))
if ('uls' in conf.quantity_check
and record.ul_quantity > record.loaded_uls):
warning_name = 'pending_uls_%s' % record.id
if Warning.check(warning_name):
raise UserWarning(warning_name, gettext(
'carrier_load_ul.msg_carrier_load_order_pending_uls',
uls=record.loaded_uls,
ul_quantity=int(record.ul_quantity)))
message = gettext('carrier_load_ul.'
'msg_carrier_load_order_pending_uls',
uls=record.loaded_uls,
ul_quantity=int(record.ul_quantity))
if in_group():
warning_name = 'pending_uls_%s' % record.id
if Warning.check(warning_name):
raise UserWarning(warning_name, message)
else:
raise UserError(message)
if ('cases' in conf.quantity_check
and record.cases_quantity > record.loaded_cases):
warning_name = 'pending_cases_%s' % record.id
if Warning.check(warning_name):
raise UserWarning(warning_name, gettext(
'carrier_load_ul.msg_carrier_load_order_pending_cases',
message = gettext(
'carrier_load_ul.'
'msg_carrier_load_order_pending_cases',
loaded_cases=record.loaded_cases,
cases_quantity=record.cases_quantity))
cases_quantity=record.cases_quantity)
if in_group():
warning_name = 'pending_cases_%s' % record.id
if Warning.check(warning_name):
raise UserWarning(warning_name, message)
else:
raise UserError(gettext)
@classmethod
def _set_loaded_unit_loads(cls, records, revert=False):

View File

@ -21,6 +21,15 @@ this repository contains the full copyright notices and license terms. -->
<field name="group" ref="group_force_load"/>
</record>
<!-- Finalize loading order with less ULs -->
<record model="res.group" id="group_do_load_pending_quantity">
<field name="name">Do Load order with pending quantity</field>
</record>
<record model="res.user-res.group" id="user_admin_group_group_do_load_pending_quantity">
<field name="user" ref="res.user_admin"/>
<field name="group" ref="group_do_load_pending_quantity"/>
</record>
<!-- Configuration -->
<record model="ir.ui.view" id="carrier_configuration_view_form">
<field name="model">carrier.configuration</field>

View File

@ -433,6 +433,10 @@ msgctxt "model:res.group,name:group_force_load"
msgid "Force UL load"
msgstr "Forzar carga de UdCs"
msgctxt "model:res.group,name:group_do_load_pending_quantity"
msgid "Do Load order with pending quantity"
msgstr "Finalizar orden de carga con cantidades pendientes"
msgctxt "report:carrier.load.purchase:"
msgid "Carrier:"
msgstr "Transportista:"

View File

@ -5,7 +5,7 @@ Carrier load UL
Imports::
>>> import datetime
>>> from trytond.tests.tools import activate_modules
>>> from trytond.tests.tools import activate_modules, set_user
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from trytond.modules.company.tests.tools import create_company, \
@ -64,6 +64,20 @@ Create parties::
>>> customer = Party(name='Customer')
>>> customer.save()
Create users::
>>> User = Model.get('res.user')
>>> Group = Model.get('res.group')
>>> admin_user, = User.find([('login', '=', 'admin')], limit=1)
>>> carrier_group, = Group.find([('name', '=', 'Carrier')])
>>> other_user = User()
>>> other_user.name = 'Other User'
>>> other_user.login = 'other_user'
>>> other_user.groups.append(carrier_group)
>>> other_user.save()
Create payment term::
>>> payment_term = create_payment_term()
@ -627,4 +641,69 @@ Check sale::
>>> order.sale.state == conf.sale_state
True
>>> order.sale.state
'draft'
'draft'
Create carrier load::
>>> load = Load()
>>> load.carrier = carrier
>>> load.vehicle_number = 'MX3449'
>>> load.save()
Create load order::
>>> order = Order(load=load)
>>> order.start_date = datetime.datetime.now()
>>> order.party = customer
>>> line = order.lines.new()
>>> line.ul_quantity = Decimal(2)
>>> order.save()
>>> order.click('wait')
>>> order.state
'waiting'
Create unit load::
>>> uni_load = create_unit_load(config=config,
... product=template.products[0],
... default_values={'start_date': datetime.datetime.now() + relativedelta(days=-1)})
Starting load wizard::
>>> start_load = Wizard('carrier.load_uls', [order])
>>> start_load.form.ul_code = uni_load.code
>>> start_load.execute('load_')
>>> order.reload()
>>> order.ul_quantity > order.loaded_uls
True
Change User::
>>> set_user(other_user)
Do load order::
>>> order.click('do') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
trytond.exceptions.UserError: You have loaded less ULs (...) than expected (...). -
>>> order.state
'running'
Change User::
>>> set_user(admin_user)
Do load order again::
>>> order.reload()
>>> order.click('do') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
trytond.exceptions.UserWarning: You have loaded less ULs (...) than expected (...). -
>>> Model.get('res.user.warning')(user=config.user,
... name='pending_uls_%s' % order.id,
... always=True).save()
>>> order.click('do')
>>> order.state
'done'