New user group to allow do load order with pending quantity.
This commit refs #25529
This commit is contained in:
parent
e7e8b8ecec
commit
992af4b969
46
load.py
46
load.py
|
@ -437,10 +437,26 @@ class LoadOrder(metaclass=PoolMeta):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _check_loaded_quantity(cls, records):
|
def _check_loaded_quantity(cls, records):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Warning = pool.get('res.user.warning')
|
|
||||||
Configuration = pool.get('carrier.configuration')
|
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)
|
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:
|
for record in records:
|
||||||
if not record.unit_loads:
|
if not record.unit_loads:
|
||||||
raise UserError(gettext(
|
raise UserError(gettext(
|
||||||
|
@ -448,20 +464,32 @@ class LoadOrder(metaclass=PoolMeta):
|
||||||
order=record.rec_name))
|
order=record.rec_name))
|
||||||
if ('uls' in conf.quantity_check
|
if ('uls' in conf.quantity_check
|
||||||
and record.ul_quantity > record.loaded_uls):
|
and record.ul_quantity > record.loaded_uls):
|
||||||
|
|
||||||
|
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
|
warning_name = 'pending_uls_%s' % record.id
|
||||||
if Warning.check(warning_name):
|
if Warning.check(warning_name):
|
||||||
raise UserWarning(warning_name, gettext(
|
raise UserWarning(warning_name, message)
|
||||||
'carrier_load_ul.msg_carrier_load_order_pending_uls',
|
else:
|
||||||
uls=record.loaded_uls,
|
raise UserError(message)
|
||||||
ul_quantity=int(record.ul_quantity)))
|
|
||||||
if ('cases' in conf.quantity_check
|
if ('cases' in conf.quantity_check
|
||||||
and record.cases_quantity > record.loaded_cases):
|
and record.cases_quantity > record.loaded_cases):
|
||||||
|
message = gettext(
|
||||||
|
'carrier_load_ul.'
|
||||||
|
'msg_carrier_load_order_pending_cases',
|
||||||
|
loaded_cases=record.loaded_cases,
|
||||||
|
cases_quantity=record.cases_quantity)
|
||||||
|
if in_group():
|
||||||
warning_name = 'pending_cases_%s' % record.id
|
warning_name = 'pending_cases_%s' % record.id
|
||||||
if Warning.check(warning_name):
|
if Warning.check(warning_name):
|
||||||
raise UserWarning(warning_name, gettext(
|
raise UserWarning(warning_name, message)
|
||||||
'carrier_load_ul.msg_carrier_load_order_pending_cases',
|
else:
|
||||||
loaded_cases=record.loaded_cases,
|
raise UserError(gettext)
|
||||||
cases_quantity=record.cases_quantity))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _set_loaded_unit_loads(cls, records, revert=False):
|
def _set_loaded_unit_loads(cls, records, revert=False):
|
||||||
|
|
9
load.xml
9
load.xml
|
@ -21,6 +21,15 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="group" ref="group_force_load"/>
|
<field name="group" ref="group_force_load"/>
|
||||||
</record>
|
</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 -->
|
<!-- Configuration -->
|
||||||
<record model="ir.ui.view" id="carrier_configuration_view_form">
|
<record model="ir.ui.view" id="carrier_configuration_view_form">
|
||||||
<field name="model">carrier.configuration</field>
|
<field name="model">carrier.configuration</field>
|
||||||
|
|
|
@ -433,6 +433,10 @@ msgctxt "model:res.group,name:group_force_load"
|
||||||
msgid "Force UL load"
|
msgid "Force UL load"
|
||||||
msgstr "Forzar carga de UdCs"
|
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:"
|
msgctxt "report:carrier.load.purchase:"
|
||||||
msgid "Carrier:"
|
msgid "Carrier:"
|
||||||
msgstr "Transportista:"
|
msgstr "Transportista:"
|
||||||
|
|
|
@ -5,7 +5,7 @@ Carrier load UL
|
||||||
Imports::
|
Imports::
|
||||||
|
|
||||||
>>> import datetime
|
>>> import datetime
|
||||||
>>> from trytond.tests.tools import activate_modules
|
>>> from trytond.tests.tools import activate_modules, set_user
|
||||||
>>> from dateutil.relativedelta import relativedelta
|
>>> from dateutil.relativedelta import relativedelta
|
||||||
>>> from decimal import Decimal
|
>>> from decimal import Decimal
|
||||||
>>> from trytond.modules.company.tests.tools import create_company, \
|
>>> from trytond.modules.company.tests.tools import create_company, \
|
||||||
|
@ -64,6 +64,20 @@ Create parties::
|
||||||
>>> customer = Party(name='Customer')
|
>>> customer = Party(name='Customer')
|
||||||
>>> customer.save()
|
>>> 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::
|
Create payment term::
|
||||||
|
|
||||||
>>> payment_term = create_payment_term()
|
>>> payment_term = create_payment_term()
|
||||||
|
@ -628,3 +642,68 @@ Check sale::
|
||||||
True
|
True
|
||||||
>>> order.sale.state
|
>>> 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'
|
||||||
|
|
Loading…
Reference in New Issue