Commit c60c02a8 authored by Titouan Soulard's avatar Titouan Soulard

erp5_trade: rework `isQuantityEnabled` and `isQuantityEditable` scripts

The two scripts were a bit too independant from one another, sometimes causing
weird behaviours. Editing a quantity now depends on the quantity being enabled,
which happens when the line is not expected to have cells or sublines.

Also enforces expected behaviour for items: if a product or service has
*required* items, its quantity cannot be edited, since quantity of the items
should set the quantity of the line or cell.
parent 44e42749
"""This script is used to know if quantity can be edited by user.
* If this is not a movement (line containing lines or cell), user
cannot edit this line which is just a container, but no actual movement.
"""
This script is used to know if quantity can be edited by user.
* If this line has variation category list, then it means it's a line that
will contain cell, so it's already not possible to set quantity, user have
to create cells and set quantities on cells.
* If quantity is not enabled on the movement, quantity cannot be set.
* If items are used, quantity is set by the item quantity.
* If items are required, quantity is set by the item quantity.
"""
if not context.isMovement():
return False
if context.getVariationCategoryList(omit_optional_variation=1) and not 'Cell' in context.getPortalType():
if not context.Movement_isQuantityEnabled():
return False
return not (context.getResource() and context.getResourceValue().getAggregatedPortalTypeList())
return not (context.getResource() and context.getResourceValue().getRequiredAggregatedPortalTypeList())
return context.isMovement() and not context.getVariationCategoryList()
"""
This script is used to know if quantity should be shown to the user. Usually, not showing quantity happens when a total quantity is shown instead, meaning the line uses cells.
* If this is not a movement (line containing lines or cell), user cannot see quantity for this line which is just a container, but no actual movement.
* If this line has required variation category list, then it means it's a line that will contain cell, so total quantity will be used instead.
* If this line has optional variation category list, and already contain cells, total quantity should also be used.
"""
if not context.isMovement():
return False
if not 'Cell' in context.getPortalType() and \
(context.getVariationCategoryList(omit_optional_variation=1) or \
context.hasCellContent(base_id='movement')):
return False
return True
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment