示例#1
0
def edit_stock(stock_id):
    stock_data = request.json
    query = Stock.queryNotSoftDeleted().filter_by(id=dehumanize(stock_id))
    stock = query.first_or_404()
    check_offer_is_editable(stock.offer)
    check_dates_are_allowed_on_existing_stock(stock_data, stock.offer)
    offerer_id = stock.resolvedOffer.venue.managingOffererId
    ensure_current_user_has_rights(RightsType.editor, offerer_id)

    stock.populate_from_dict(stock_data)
    PcObject.save(stock)

    return jsonify(as_dict(stock)), 200
示例#2
0
def test_queryNotSoftDeleted_should_not_return_soft_deleted(app):
    # Given
    offerer = create_offerer()
    venue = create_venue(offerer)
    stock = create_stock_with_event_offer(offerer, venue)
    stock.isSoftDeleted = True
    PcObject.save(stock)

    # When
    result = Stock.queryNotSoftDeleted().all()

    # Then
    assert not result
示例#3
0
 def lastStock(self):
     query = Stock.queryNotSoftDeleted()
     return query.join(Offer) \
         .filter(Offer.id == self.id) \
         .order_by(desc(Stock.bookingLimitDatetime)) \
         .first()