Allow pending product fields to be required, for new custorder

This commit is contained in:
Lance Edgar 2023-10-24 19:17:36 -05:00
parent e308108bf7
commit 4247804707
3 changed files with 167 additions and 57 deletions

View file

@ -102,6 +102,19 @@ class CustomerOrderView(MasterView):
'flagged',
]
PENDING_PRODUCT_ENTRY_FIELDS = [
'key',
'department_uuid',
'brand_name',
'description',
'size',
'vendor_name',
'vendor_item_code',
'unit_cost',
'case_size',
'regular_price_amount',
]
def __init__(self, request):
super(CustomerOrderView, self).__init__(request)
self.batch_handler = self.get_batch_handler()
@ -361,6 +374,7 @@ class CustomerOrderView(MasterView):
'order_items': items,
'product_key_label': app.get_product_key_label(),
'allow_unknown_product': self.batch_handler.allow_unknown_product(),
'pending_product_required_fields': self.get_pending_product_required_fields(),
'department_options': self.get_department_options(),
'default_uom_choices': self.batch_handler.uom_choices_for_product(None),
'default_uom': None,
@ -390,6 +404,17 @@ class CustomerOrderView(MasterView):
'value': department.uuid})
return options
def get_pending_product_required_fields(self):
required = []
for field in self.PENDING_PRODUCT_ENTRY_FIELDS:
require = self.rattail_config.getbool('rattail.custorders',
f'unknown_product.fields.{field}.required')
if require is None and field == 'description':
require = True
if require:
required.append(field)
return required
def get_current_batch(self):
user = self.request.user
if not user:
@ -1044,7 +1069,7 @@ class CustomerOrderView(MasterView):
}
def configure_get_simple_settings(self):
return [
settings = [
# customer handling
{'section': 'rattail.custorders',
@ -1067,9 +1092,6 @@ class CustomerOrderView(MasterView):
{'section': 'rattail.custorders',
'option': 'product_price_may_be_questionable',
'type': bool},
{'section': 'rattail.custorders',
'option': 'allow_unknown_product',
'type': bool},
{'section': 'rattail.custorders',
'option': 'allow_item_discounts',
'type': bool},
@ -1082,8 +1104,30 @@ class CustomerOrderView(MasterView):
{'section': 'rattail.custorders',
'option': 'allow_past_item_reorder',
'type': bool},
# unknown products
{'section': 'rattail.custorders',
'option': 'allow_unknown_product',
'type': bool},
]
for field in self.PENDING_PRODUCT_ENTRY_FIELDS:
setting = {'section': 'rattail.custorders',
'option': f'unknown_product.fields.{field}.required',
'type': bool}
if field == 'description':
setting['default'] = True
settings.append(setting)
return settings
def configure_get_context(self, **kwargs):
context = super().configure_get_context(**kwargs)
context['pending_product_fields'] = self.PENDING_PRODUCT_ENTRY_FIELDS
return context
@classmethod
def defaults(cls, config):
cls._order_defaults(config)