Example #1
0
    def add_product_and_price(self, product_name, price_name):
        product = yield dbfind(products_table, 'name', product_name)
        price = yield dbfind(prices_table, 'name', price_name)

        print "Using prouct:", product
        print "Using price:", price

        row = offer_product_prices_table.insert()
        row.execute(id=genid(), offer_id=self.id, product_id=product.id, price_id=price.id)
        yield Just(self)
Example #2
0
    def create(cls, price_dict):

        price = dict_to_namedtuple("Price", price_dict)
        old_price = dbfind(prices_table, 'name', price.name)

        if isinstance(old_price, Right):
            yield ( old_price >> (lambda v: Left("Price with name %s already exists!" % (price.name,))) )

        row = prices_table.insert()
        row.execute(id = genid(), name = price.name, description = price.description, rate=price.rate, uom=price.uom)
        row = dbfind(prices_table, 'name', price.name)
        yield Right( row >> (lambda v: Price(v)) )
Example #3
0
    def create(cls, offer_dict):

        offer = dict_to_namedtuple("Offer", offer_dict)
        old_offer = dbfind(offers_table, 'name', offer.name)

        if isinstance(old_offer, Right):
            yield ( old_offer >> (lambda v: Left("Offer with name %s already exists!" % (offer.name,))) )

        row = offers_table.insert()
        row.execute(id = genid(), name = offer.name, description = offer.description)
        row = dbfind(offers_table, 'name', offer.name)
        yield Right( row >> (lambda v: Offer(v)) )
Example #4
0
    def create(cls, product_dict):

        product = dict_to_namedtuple("Product", product_dict)
        old_product = dbfind(products_table, 'name', product.name)

        if isinstance(old_product, Right):
            yield ( old_product >> (lambda v: Left("Product with name %s already exists!" % (product.name,))) )

        row = products_table.insert()
        row.execute(id = genid(), name = product.name, description = product.description)
        row = dbfind(products_table, 'name', product.name)
        yield Right( row >> (lambda v: Product(v)) )