In the sweetscomplete.domain.purchase.PurchaseService class, we need to define a method that adds a document to the database. As with the other domain service classes described earlier in this chapter, we import the Base domain service class, as well as the Purchase entity class. In addition, we need access to the ObjectId and CursorType classes, as shown here:
from sweetscomplete.domain.base import Base
from sweetscomplete.entity.purchase import Purchase
from bson.objectid import ObjectId
from pymongo.cursor import CursorType
class PurchaseService(Base) :
As you may recall from a discussion earlier in this chapter, a decision needs to be made about the extended price of a purchase. In this implementation, we calculate the extended price just prior to storage, as shown here. The addOne() method then returns the new ObjectId, or a boolean False value if the insertion failed:
def addOne(self, purchaseEntity) :
extPrice = 0...