diff --git a/commerce/README.txt b/commerce/README.txt index 37d3dd1..9c38be5 100644 --- a/commerce/README.txt +++ b/commerce/README.txt @@ -115,7 +115,8 @@ Orders The items in a shopping cart may be included in an order. - >>> ord001 = manager.orders.create(u'001', shop=shop1, customer=c001) + >>> orderId = shop1.getNewOrderId() + >>> ord001 = manager.orders.create(orderId, shop=shop1, customer=c001) >>> for item in orderItems.getCart(c001): ... item.setOrder(ord001) diff --git a/commerce/interfaces.py b/commerce/interfaces.py index c31a223..a4efd6f 100644 --- a/commerce/interfaces.py +++ b/commerce/interfaces.py @@ -76,6 +76,13 @@ class IShop(Interface): description=_(u'A medium-length description.'), default=u'', required=False) + orderNumber = schema.Int( + title=_(u'Order Number'), + description=_(u'The number used for the order identifier of ' + u'last order created. This will in turn be used ' + u'for creating the next order identifier.'), + default=0, + required=False) products = Attribute(u'The products available in this shop.') categories = Attribute(u'The product categories provided by this shop.') @@ -85,6 +92,10 @@ class IShop(Interface): u'this shop.') customers = Attribute(u'The customers registered for this shop.') + def getNewOrderId(): + """ Create a new order identifier. + """ + # manufacturers and suppliers diff --git a/commerce/shop.py b/commerce/shop.py index 3290916..98afa61 100644 --- a/commerce/shop.py +++ b/commerce/shop.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2008 Helmut Merz helmutm@cy55.de +# Copyright (c) 2009 Helmut Merz helmutm@cy55.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,3 +39,10 @@ class Shop(BaseObject): self.title = title or u'Shop' self.products = self.collection(self, 'shops') self.customers = self.collection(self, 'shops') + self.orderNumber = 0 + + def getNewOrderId(self): + last = self.orderNumber or 0 + num = last + 1 + self.orderNumber = num + return '%05i' % num