parent
4f3ee63faf
commit
ed324ec4e3
@ -1,25 +1,12 @@
|
|||||||
from marshmallow import Schema, fields, ValidationError
|
from marshmallow import Schema, fields
|
||||||
|
|
||||||
|
|
||||||
def non_neg(value):
|
|
||||||
if not value >= 0:
|
|
||||||
raise ValidationError('Value cannot be negative')
|
|
||||||
|
|
||||||
|
|
||||||
def non_neg_non_zero(value):
|
|
||||||
if not value > 0:
|
|
||||||
raise ValidationError('Value cannot be negative or zero')
|
|
||||||
|
|
||||||
|
|
||||||
class CookieSchema(Schema):
|
class CookieSchema(Schema):
|
||||||
id = fields.Int(dump_only=True)
|
id = fields.Int()
|
||||||
created_date = fields.DateTime(dump_only=True)
|
created_date = fields.DateTime()
|
||||||
modified_date = fields.DateTime()
|
modified_date = fields.DateTime()
|
||||||
name = fields.Str(required=True, error_messages={'required': "Cookie name is required"})
|
name = fields.Str(required=True)
|
||||||
recipe_url = fields.Str()
|
recipe_url = fields.Str()
|
||||||
sku = fields.Str(required=True, error_messages={'required': "Cookie sku is required"})
|
sku = fields.Str(required=True)
|
||||||
qoh = fields.Int(validate=non_neg, required=True, error_messages={'required': "Cookie qoh is required"})
|
qoh = fields.Int(required=True)
|
||||||
unit_cost = fields.Decimal(validate=non_neg_non_zero, required=True, error_messages={'required': "Cookie unit_cost is required"})
|
unit_cost = fields.Decimal(required=True)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordered = True
|
|
||||||
|
Loading…
Reference in New Issue