Пример #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 test_save_existing(self):
     ent = Enterprise.find_by_name('Healthy U Store')
     category_id = self._create_new()
     R = self.get('/crm/product/category/list')
     assert R.status_int == 200
     R.mustcontain('Test Category')
     R.mustcontain('Product Search')
     R = self.get('/crm/product/category/edit/%s' % category_id)
     R.mustcontain('Edit Product Category')
     f = R.forms['frm_category']
     self.assertEqual(f['category_id'].value, category_id)
     self.assertEqual(f['name'].value, 'Test Category')
     self.assertEqual(f['seo_keywords'].value, 'SEO Test')
     self.assertEqual(f['description'].value, 'Test Description')
     f.set('name', 'Test Category New')
     f.set('seo_keywords', 'SEO Test New')
     for prd in Product.find_all(ent.enterprise_id)[:3]:
         f.set('child_incl_%s' % prd.product_id, prd.product_id)
     R = f.submit('submit')
     self.assertEqual(R.status_int, 302)
     R = R.follow()
     assert R.status_int == 200
     f = R.forms['frm_category']
     R.mustcontain('Edit Product Category')
     self.assertEqual(f['category_id'].value, category_id)
     self.assertEqual(f['name'].value, 'Test Category New')
     self.assertEqual(f['seo_keywords'].value, 'SEO Test New')
     for prd in Product.find_all(ent.enterprise_id)[:3]:
         self.assertEqual(f['child_incl_%s' % prd.product_id].checked, True)
     self._delete_new(category_id)
Пример #3
0
    def _show_prep(self, report_id):
        report = Report.load(report_id)
        campaigns = products = companies = users = vendors = None
        if report.show_campaign_id:
            campaigns = util.select_list(Campaign.find_all(self.enterprise_id), 'campaign_id', 'name', True)

        if report.show_vendor_id:
            vendors = util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name', True)

        if report.show_company_id:
            companies = util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name', True)

        if report.show_user_id:
            users = util.select_list(Users.find_all(self.enterprise_id), 'user_id', 'user_id', True)

        if report.show_product_id:
            products = util.select_list(Product.find_all(self.enterprise_id), 'product_id', 'name', True)

        return {
            'today' : util.today_date(),
            'tomorrow' : util.tomorrow(),
            'thirty_ago' : util.today_date() - datetime.timedelta(days=30),
            'rpt_end_dt' : self.request.GET.get('rpt_end_dt'),
            'rpt_start_dt' : self.request.GET.get('rpt_start_dt'),
            'enterprise_id' : self.enterprise_id,
            'report' : report,
            'campaigns' : campaigns,
            'products' : products,
            'companies' : companies,
            'users' : users,
            'vendors' : vendors
            }
Пример #4
0
 def _edit_impl(self):
     purchase_order_id = self.request.matchdict.get('purchase_order_id')
     purchase = PurchaseOrder.load(purchase_order_id) if purchase_order_id else PurchaseOrder()
     return {
         'companies' : util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name'),
         'vendors' : util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name', True),
         'products' : Product.find_all(self.enterprise_id),
         'purchase' : purchase,
         'events' : util.select_list(StatusEvent.find_all_applicable(self.enterprise_id, purchase), 'event_id', 'display_name') if purchase.purchase_order_id else []
         }
Пример #5
0
    def _edit_impl(self):
        category_id = self.request.matchdict.get('category_id')
        companies = util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name')
        if category_id:
            category = ProductCategory.load(category_id)
            self.forbid_if(not category or category.company.enterprise_id != self.enterprise_id)
        else:
            category = ProductCategory()

        all_products = Product.find_all(self.enterprise_id)
        return {'companies' : companies,
                'category' : category,
                'all_products' : all_products}
Пример #6
0
    def test_complete_po(self):
        purchase_order_id = self._create_new()

        ent = Enterprise.find_by_name('Healthy U Store')
        prods = Product.find_all(ent.enterprise_id)
        product_id = prods[0].product_id

        # add a new one
        R = self.post('/crm/purchase/save_purchase_order_item/%s?product_id=%s' % (str(purchase_order_id), product_id),
                      {'order_note' : 'Note Note',
                       'quantity' : 10,
                       'unit_cost' : 123})
        json.loads(R.body)
        assert R.status_int == 200

        R = self.get('/crm/purchase/complete/%s' % purchase_order_id)
        assert R.status_int == 200
        R.mustcontain('True')
        R = self.get('/crm/purchase/edit/%s' % purchase_order_id)
        assert R.status_int == 200
        R.mustcontain('Completed:')
        self._delete_new(purchase_order_id)
Пример #7
0
    def test_order_item_add_delete(self):
        ent = Enterprise.find_by_name('Healthy U Store')
        purchase_order_id = self._create_new()
        prods = Product.find_all(ent.enterprise_id)
        product_id = prods[0].product_id

        # add a new one
        R = self.post('/crm/purchase/save_purchase_order_item/%s?product_id=%s' % (str(purchase_order_id), product_id),
                      {'order_note' : 'Note Note',
                       'quantity' : 10,
                       'unit_cost' : 123})
        oitem = json.loads(R.body)
        assert R.status_int == 200
        order_item_id = oitem['id']

        # get the json from it
        R = self.get('/crm/purchase/order_item_json/%s/%s' % (purchase_order_id, order_item_id))
        assert R.status_int == 200
        oitem = json.loads(R.body)
        self.assertEqual(oitem['order_item_id'], order_item_id)
        self.assertEqual(oitem['note'], 'Note Note')
        self.assertEqual(int(oitem['unit_cost']), 123)
        self.assertEqual(int(oitem['quantity']), 10)

        # complete the item
        R = self.get('/crm/purchase/complete_item/%s/%s' % (purchase_order_id, order_item_id))
        assert R.status_int == 200
        R.mustcontain('True')

        #R = self.get('/crm/purchase/show_history/%s' % purchase_order_id)
        #assert R.status_int == 200
        #R.mustcontain('PurchaseOrder Completed')

        # delete the oi
        R = self.get('/crm/purchase/delete_purchase_order_item/%s/%s' % (purchase_order_id, order_item_id))
        assert R.status_int == 200
        R.mustcontain('True')
        
        self._delete_new(purchase_order_id)
Пример #8
0
 def list(self):
     return {'products' : Product.find_by_vendor(self.enterprise_id,
                                                 self.request.ctx.user.vendor) \
                 if self.request.ctx.user.is_vendor_user() \
                 else Product.find_all(self.enterprise_id)}
Пример #9
0
    def inventory_list(self):
        products = Product.find_by_vendor(self.request.ctx.user.vendor) if self.request.ctx.user and self.request.ctx.user.is_vendor_user() else Product.find_all(self.enterprise_id) #pylint: disable-msg=E1120

        campaigns = Campaign.find_all(self.enterprise_id)

        response = {
            'page': 1,
            'total': 1,
            'records': len(products)}

        rows = []

        for prod in products:
            #log.debug('%s %s/%s' % (p.product_id, i+1, len(products)))
            # blank spot at the beginning of the row is to make room for the
            # action buttons.  don't remove it.
            cells = ['', unicode(prod.product_id),
                     util.nvl(prod.name),
                     util.nvl(prod.sku),
                     util.nvl(prod.manufacturer),
                     util.nvl(unicode(prod.inventory)),
                     util.nvl(unicode(prod.inventory_par)),
                     util.nvl(unicode(prod.unit_cost))]
            # the column ordering in the UI is dependant on the order of the
            # campaigns that comes back from Campaign.find_all().  We use the
            # same ordering here so we are fine not adding some campaign ID here.
            for camp in campaigns:
                cells.append(util.nvl(util.money(prod.get_retail_price(camp))))

            rows.append({'id': str(prod.product_id),
                         'cell': cells})

        response['rows'] = rows
        return json.dumps(response)
Пример #10
0
 def get_prods(self):
     ent = Enterprise.find_all()[0]
     prods = Product.find_all(ent.enterprise_id)
     assert len(prods) > 0
     return prods