示例#1
0
 def save_vendor(self):
     ent = Vendor.load(self.request.POST.get('vendor_id'))
     if not ent:
         ent = Vendor()
     ent.bind(self.request.POST, True)
     ent.enterprise_id = self.enterprise_id
     ent.save()
     ent.flush()
     self.flash('Successfully saved %s.' % ent.name)
     return HTTPFound('/crm/purchase/vendor/edit/%s' % ent.vendor_id)
示例#2
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
            }
示例#3
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 []
         }
示例#4
0
 def search(self):
     vendor_id = self.request.POST.get('vendor_id') 
     from_dt = self.request.POST.get('from_dt', util.str_today())
     to_dt = self.request.POST.get('to_dt', util.str_today())
     return {
         'vendor_id' : vendor_id, 
         'from_dt' : from_dt, 
         'to_dt' : to_dt, 
         'purchases' : PurchaseOrder.search(self.enterprise_id, vendor_id, from_dt, to_dt),
         'vendors' : util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name')
         }
示例#5
0
 def _edit_impl(self, user_id=None):
     user = priv = None
     if user_id:
         user = self.request.ctx.user if self.request.ctx.user.user_id == user_id else Users.load(user_id)
         priv = user.priv if user.priv else UserPriv()
     else:
         user = Users()
         priv = UserPriv()
     return {
         'enterprises' : util.select_list(Enterprise.find_all(), 'enterprise_id', 'name', True),
         'user_types': Users.get_user_types(),
         'vendors' : util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name', True),
         'timezones' : country_timezones('US'),
         'user' : user,
         'priv' : priv
         }
示例#6
0
    def _edit_impl(self):
        product_id = self.request.matchdict.get('product_id')
        campaigns = Campaign.find_all(self.enterprise_id)
        companies = util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name')
        product_types = Product.get_types()
        vendors = util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name', True)
        categories = util.select_list(ProductCategory.find_all(self.enterprise_id), 'category_id', 'name', True)
        if product_id:
            product = Product.load(product_id)
            self.forbid_if(not product or product.company.enterprise_id != self.enterprise_id)
            product_categories = ProductCategory.find_by_product(product)
        else:
            product = Product()
            product_categories = []
        self.forbid_if(self.request.ctx.user.is_vendor_user() and product.product_id and not self.request.ctx.user.vendor_id == product.vendor_id)
        children = product.get_children()
        other_products = product.find_eligible_children()
        non_children = []
        for prod in other_products:
            found = False
            for kid in children:
                if kid.child_id == prod.product_id:
                    found = True
                    break
            if found == False:
                non_children.append(prod)

        return  {
            'product' : product,
            'campaigns' : campaigns,
            'companies' : companies,
            'product_types' : product_types,
            'vendors' : vendors,
            'categories' : categories,
            'product_categories' : product_categories,
            'children' : children,
            'non_children': non_children,
            'other_products' : other_products,
            'events' : util.select_list(StatusEvent.find_all_applicable(self.enterprise_id, product), 'event_id', 'display_name'),
            'is_attribute' : self.request.GET.get('is_attribute') == 'True', 
            'parent_product' : Product.load(self.request.GET.get('parent_id')) if 'parent_id' in self.request.GET else None
            }
示例#7
0
    def _create_new(self):
        ent = Enterprise.find_by_name('Healthy U Store')
        vendors = Vendor.find_all(ent.enterprise_id)
        ven = vendors[0]

        R = self.get('/crm/purchase/new')
        assert R.status_int == 200
        R.mustcontain('Edit Supplier Order')
        f = R.forms['frm_purchase']
        self.assertEqual(f['purchase_order_id'].value, '')
        f.set('vendor_id', ven.vendor_id)
        f.set('shipping_cost', 123.45)
        f.set('note', 'Test Purchase Order')
        
        R = f.submit()
        self.assertEqual(R.status_int, 302)
        R = R.follow()
        assert R.status_int == 200
        f = R.forms['frm_purchase']
        R.mustcontain('Edit Supplier Order')
        purchase_order_id = f['purchase_order_id'].value
        self.assertNotEqual(f['purchase_order_id'].value, '')
        return purchase_order_id
示例#8
0
 def _delete_new_vendor(self, vendor_id):
     ven = Vendor.load(vendor_id)
     self.assertNotEqual(ven, None)
     ven.delete()
     self.commit()
示例#9
0
 def show_search(self):
     return {
         'vendors' : util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name'),
         'purchases' : None
         }
示例#10
0
 def list_vendors(self):
     return {'vendors' : Vendor.find_all(self.enterprise_id) }
示例#11
0
 def _edit_vendor_impl(self):
     vendor_id = self.request.matchdict.get('vendor_id')
     return {'vendor' : Vendor.load(vendor_id) if vendor_id else Vendor() }