def create_offer_item_from_dict(product_dict, product_offer_id): offer_item = OfferItem( product_offer_id=product_offer_id, master_product_id=product_dict['master_product_id'], name=product_dict.get('wine_name') or '', score_num=to_int(product_dict.get('rating')), image=product_dict['img_url'], price=to_decimal(product_dict.get('price')), description=product_dict.get('short_desc', ''), location=product_dict.get('region', ''), brand=product_dict.get('brand', ''), sku=product_dict.get('sku', ''), qoh=product_dict.get('qoh'), msrp=to_decimal(product_dict.get('msrp')), product_url=product_dict.get('product_url'), highlights=product_dict.get('highlights'), varietals=product_dict.get('varietals'), best_theme_id=to_int(product_dict.get('best_theme')) ) db.session.add(offer_item) db.session.flush() offer_item.prof_reviews = [{ 'name': r.reviewer_name, 'score': to_int(r.review_score) } for r in offer_item.product_reviews if r.review_score] # TODO otereshchenko: optimize db fetching of offer_item.product_reviews for batch return offer_item
def accepted_offer_item( user, master_product_1, accepted_product_offer, support_notified_order, source_1, theme_1 ): item = OfferItem( product_offer_id=accepted_product_offer.id, master_product_id=master_product_1.id, name='wine name', score_num=99, image='img_url', price=Decimal(80), description='Short description', location='Region', brand='brand', highlights=['Highlights'], varietals=['Varietals'], sku='123', qoh=1, msrp=Decimal('3.99'), product_url='http://product', best_theme=theme_1, ) db.session.add(item) db.session.commit() yield item
def proposed_to_user_offer_item( user, master_product_1, proposed_to_user_product_offer, proposed_to_user_order, source_1, theme_1 ): item = OfferItem( product_offer_id=proposed_to_user_product_offer.id, master_product_id=master_product_1.id, name='wine name', score_num=99, image='img_url', price=Decimal(80), description='Short description', location='Region', brand='brand', highlights=['Highlights'], varietals=['Varietals'], prof_reviews=[ {'score': 90, 'name': 'reviewer 1 2'}, {'score': 80, 'name': 'reviewer 1 1'}, ], sku='123', qoh=1, msrp=Decimal('3.99'), product_url='http://product', best_theme=theme_1, ) db.session.add(item) db.session.commit() yield item
def _populate_offer_items(offer, master_product, best_theme): for i in range(3): item = OfferItem( product_offer_id=offer.id, master_product_id=master_product.id, name='wine name' + str(i), score_num=99 + i, image='img_url', price=Decimal(80 + 1), description='Short description', location='Region', brand='brand', highlights=['Highlights'], varietals=['Varietals'], sku='123', qoh=1, msrp=Decimal('3.99'), product_url='http://product', best_theme=best_theme, ) db.session.add(item) db.session.commit()