예제 #1
0
    def _edit_impl(self):
        discount_id = self.request.matchdict.get('discount_id')
        discount = None
        if discount_id:
            discount = Discount.load(discount_id)
            self.forbid_if(not discount or discount.enterprise_id != self.enterprise_id)
        else:
            discount = Discount()

        included_products = discount.get_products()
        not_included_products = []
        for prod in Product.find_all(self.enterprise_id):
            found = False
            for incl in included_products:
                if incl.product_id == prod.product_id:
                    found = True
                    break
            if found == False:
                not_included_products.append(prod)

        return {
            'discount': discount,
            'included_products' : included_products,
            'not_included_products' : not_included_products,
            'excluded' : Product.find_all(self.enterprise_id),
            'tomorrow' : util.today_date() + datetime.timedelta(days=1),
            'plus14' : util.today_date() + datetime.timedelta(days=14)
            }
예제 #2
0
def create_new_product_discount(testcase, automatic=False):
    R = testcase.get('/crm/discount/new')
    assert R.status_int == 200
    R.mustcontain('Edit Discount')
    f = R.forms['frm_discount']
    testcase.assertEqual(f['discount_id'].value, '')
    f.set('name', 'Test Discount')
    f.set('code', 'tst101')
    f.set('description', 'tst101 description')
    f.set('percent_off', '10')
    f['web_enabled'] = True
    f['cart_discount'] = False
    f['automatic'] = automatic
    prods = testcase.get_prods()
    for prd in prods[:10]:
        f['product_incl_%s' % str(prd.product_id)] = True
    R = f.submit('submit')
    testcase.assertEqual(R.status_int, 302)
    R = R.follow()
    assert R.status_int == 200
    f = R.forms['frm_discount']
    R.mustcontain('Edit Discount')
    discount_id = f['discount_id'].value
    testcase.assertNotEqual(f['discount_id'].value, '')
    for prd in prods[:10]:
        testcase.assertEqual(f['product_incl_%s' % str(prd.product_id)].checked, True)
    disc = Discount.load(discount_id)
    assert len(disc.get_products()) == 10
    assert disc is not None
    return discount_id
예제 #3
0
 def delete(self):
     discount_id = self.request.matchdict.get('discount_id')
     discount = Discount.load(discount_id)
     self.forbid_if(not discount or str(discount.enterprise_id) != str(self.enterprise_id))
     discount.mod_dt = util.now()
     discount.delete_dt = util.now()
     discount.invalidate_caches()
     return 'True'
예제 #4
0
def delete_new_product_discount(testcase, discount_id):
    disc = Discount.load(discount_id)
    testcase.assertNotEqual(disc, None)
    prods = disc.get_products()
    assert len(prods) > 0
    for prd in prods:
        prd.delete()
    disc.delete()
    testcase.commit()
예제 #5
0
파일: cart.py 프로젝트: anonymoose/pvscore
 def save_discount(self):
     """ KB: [2013-03-11]: If they entered a discount code apply that one. """
     if not 'cart' in self.session:
         return 'True'  #pragma: no cover
     cart = self.session['cart']
     discount_code = self.request.POST.get('discount_code')
     cust = self.request.ctx.customer
     self.redir_if(not cust or not cart)
     cart.set_user_discount(Discount.find_by_code(self.enterprise_id, discount_code))
     self.session.changed()
     return self.find_redirect()
예제 #6
0
파일: cart.py 프로젝트: anonymoose/pvscore
 def inspect_cart_discounts(self, enterprise_id):
     """ KB: [2013-03-11]: Look for cart discounts.
     Call this before rendering shipping and the final totals so you can see if there are any shipping discounts
     """
     if self.is_user_discount:
         return
     applicable_total = self.product_total + self.handling_total
     cart_discounts = sorted([disc for disc in Discount.find_all_automatic_cart_discounts(enterprise_id) if applicable_total > disc.cart_minimum],
                             key=operator.attrgetter('percent_off'), reverse=True)
     if len(cart_discounts) > 0:
         self.discount = cart_discounts[0]
예제 #7
0
    def test_full_checkout_with_automatic_cart_discount(self):
        ent = Enterprise.find_by_name('Healthy U Store')
        api = StripeBillingApi(ent)

        # set up the discount for the products
        self.login_crm(PVS_ROOT_UID, PVS_ROOT_PWD)
        discount_id = create_new_cart_discount(self, True)
        discount = Discount.load(discount_id)
        assert discount is not None
        assert int(discount.percent_off) == 10
        self.logout_crm_soft()

        self.login_customer()
        self._clear_cart()

        prod = self.get_prod()
        self._add_product(prod, 100)
        R = self.get('/cart/catalog_cart')
        R.mustcontain('total=2500.0')
        R.mustcontain('product_base_total=2500.0')
        R.mustcontain('product_total=2500.0')
        R.mustcontain('product_discounts=0.0')

        R = self.get('/ecom/cart/update/%s/10' % prod.product_id)
        assert R.status_int == 200
        assert R.body == 'True'

        R = self.get('/cart/catalog_cart')
        R.mustcontain('total=250.0')
        R.mustcontain('product_base_total=250.0')
        R.mustcontain('product_total=250.0')
        R.mustcontain('product_discounts=0.0')

        self._select_shipping()

        R = self.post("/crm/customer/purchase_cart",
                      {'redir' : '/ecom/page/catalog_thanks',
                      'accept_terms' : '1',
                      'bill_cc_token' : api.create_token('4242424242424242', '12', '2019', '123')})

        R.mustcontain('order total_discounts_applied = 0')
        R.mustcontain('order total_payments_due = 0.0')
        R.mustcontain('order total_item_price = 250.0')
        #R.mustcontain('order total_payments_applied = 418.53')
        #R.mustcontain('order total_price = 418.53')
        #R.mustcontain('order total_shipping_price = 18.53')

        self.logout_customer(False)

        self.login_crm(PVS_ROOT_UID, PVS_ROOT_PWD)
        #delete_new_cart_discount(self, discount_id)
        self.logout_crm_soft()
예제 #8
0
def create_new_cart_discount(testcase, automatic=False):
    R = testcase.get('/crm/discount/new')
    assert R.status_int == 200
    R.mustcontain('Edit Discount')
    f = R.forms['frm_discount']
    testcase.assertEqual(f['discount_id'].value, '')
    f.set('name', 'Test Discount')
    f.set('code', 'tst101')
    f.set('description', 'tst101 description')
    f.set('percent_off', '10')
    f['web_enabled'] = True
    f['cart_discount'] = True
    f['automatic'] = automatic
    R = f.submit('submit')
    testcase.assertEqual(R.status_int, 302)
    R = R.follow()
    assert R.status_int == 200
    f = R.forms['frm_discount']
    R.mustcontain('Edit Discount')
    discount_id = f['discount_id'].value
    testcase.assertNotEqual(f['discount_id'].value, '')
    disc = Discount.load(discount_id)
    assert disc is not None
    return discount_id
예제 #9
0
    def save(self):
        discount = Discount.load(self.request.POST.get('discount_id'))
        if not discount:
            discount = Discount()
            discount.enterprise_id = self.enterprise_id
        else:
            self.forbid_if(discount.enterprise_id != self.enterprise_id)
        discount.bind(self.request.POST, True)
        discount.save()
        discount.flush()

        included_products = {}
        for k in self.request.POST.keys():
            if k.startswith('product_incl'):
                product_id = self.request.POST.get(k)
                included_products[product_id] = 1

        for current_prod in discount.get_products():
            if current_prod.product_id not in included_products.keys():
                discount.clear_product(current_prod.product_id)
                
        for new_included_product_id in included_products.keys():
            discount.add_product(new_included_product_id)

        discount.invalidate_caches()
        self.request.session.flash('Successfully saved %s.' % discount.name)
        return HTTPFound('/crm/discount/edit/%s' % discount.discount_id)
예제 #10
0
 def list(self):
     return {'discounts' : Discount.find_all_active(self.enterprise_id)}
예제 #11
0
def delete_new_cart_discount(testcase, discount_id):
    camp = Discount.load(discount_id)
    testcase.assertNotEqual(camp, None)
    camp.delete()
    testcase.commit()