예제 #1
0
def offer(id):
    form = OfferForm()
    if id == 0:
        offer = Offer()
        offer.user = current_user
        offer.product_id = 1
        offer.created = datetime.utcnow()
    else:
        offer = Offer.query.get(id)
        if not offer:
            abort(404, _('Angebot nicht gefunden'))
        if offer.user.id != current_user.id and not current_user.has_role(
                'admin'):
            abort(403, _('Das darfst du leider nicht'))

    products = Product.query.filter(Product.active == True).all()
    form.product.choices = [(p.id, p.description) for p in products]
    if form.validate_on_submit():
        offer.active = form.active.data
        offer.price = form.price.data
        offer.stock = form.stock.data
        offer.product_id = form.product.data
        if not offer.id:
            db.session.add(offer)
        db.session.commit()
        flash(_('Gespeichert'))
        return redirect(url_for('main.offers'))
    if offer.product:
        form.product.data = offer.product.id
    form.active.data = offer.active
    form.price.data = offer.price
    form.stock.data = offer.stock
    form.supplier.data = offer.user.username
    return render_template('offer.html', form=form)
예제 #2
0
    def insert_offers(self, offer_map: Dict[int, List[Dict[str,
                                                           int]]]) -> None:
        for product_id, offers in offer_map.items():
            for offer in offers:
                offer_row = Offer.query.filter(
                    Offer.ms_id == offer['id']).first()
                if offer_row is None:
                    offer_row = Offer(product_id=product_id, ms_id=offer['id'])

                offer_row.price = offer['price']
                offer_row.items_in_stock = offer['items_in_stock']
                self.db.session.add(offer_row)
                self.db.session.commit()
예제 #3
0
 def test_new_found_sku_has_abo_price_and_device_price(self):
     product = Product(manufacturer="LG", model_name="G2 Mini",
                       product_type="PHONE")
     sku = SKU(base_product=product, stock_code="lg-g2-mini-lte-black")
     offer = Offer(
         segmentation="IND.NEW.POSTPAID.ACQ",
         sku=sku, market="IND", offer_code="NSZAS24A",
         tariff_plan_code="5F20A", contract_condition_code="24A"
     )
     offer.abo_price = 100.00
     offer.price = 90.00
     db.session.add_all([product, sku, offer])
     db.session.commit()
     self.crawler.save_new_found_skus()
     new_sku = SKU.query.filter_by(stock_code="lg-g2-mini-lte-white").first()
     new_offer = Offer.query.filter_by(sku=new_sku).first()
     self.assertEqual(new_offer.abo_price, 100.00)
     self.assertEqual(new_offer.price, 90.00)