Beispiel #1
0
    def _create_new_attribute(self, parent_product_id):
        ent = Enterprise.find_by_name('Healthy U Store')
        comp = Company.find_all(ent.enterprise_id)[0]
        R = self.get('/crm/product/new?is_attribute&parent_id=%s' % parent_product_id)
        assert R.status_int == 200
        R.mustcontain('Edit Attribute for')
        f = R.forms['frm_product']
        self.assertEqual(f['product_id'].value, '')
        f.set('parent_id', parent_product_id)
        f.set('is_attribute', 'True')
        f.set('type', 'Attr')
        f.set('name', 'Test Product')
        f.set('unit_cost', '10.00')
        f.set('sku', 'TEST-SKU-123')
        f.set('manufacturer', 'Test Manufacturer')
        f.set('attr_name[0]', 'attr0key')
        f.set('attr_value[0]', 'attr0val')
        f.set('attr_name[1]', 'attr1key')
        f.set('attr_value[1]', 'attr1val')

        for camp in Campaign.find_by_company(comp):
            f.set('campaign_price[%s]' % camp.campaign_id, 20.0)
            f.set('campaign_discount[%s]' % camp.campaign_id, 10.0)

        R = f.submit('submit')
        self.assertEqual(R.status_int, 302)
        R = R.follow()
        assert R.status_int == 200
        f = R.forms['frm_product']
        R.mustcontain('Edit Attribute for')
        product_id = f['product_id'].value
        self.assertNotEqual(f['product_id'].value, '')
        return product_id
Beispiel #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
            }
Beispiel #3
0
 def test_send_with_attachment(self):
     ent = Enterprise.find_all()[0]
     comp = Company.find_all(ent.enterprise_id)[0]
     mail = UserMail(comp.default_campaign)
     rand_subj = random.random()
     mail.send('*****@*****.**', 'test %s' % rand_subj,
               'This is generated by pvscore/tests/functional/test_mail:test_send_with_attachment',
               'README.md')
Beispiel #4
0
 def test_misc(self):
     ent = Enterprise.find_by_name('Healthy U Store')
     comps = Company.find_all(ent.enterprise_id)
     assert len(comps) > 0
     comp = comps[0]
     comp_ = Company.find_by_name(ent.enterprise_id, comp.name)
     assert comp_ is not None
     assert comp.company_id == comp_.company_id
     assert str(ent.enterprise_id) in str(ent) 
     assert ent.get_email_info() is not None
     assert comp.get_email_info() is not None
     assert Enterprise.find_by_name(ent.name).name == ent.name
     camps = Campaign.find_by_company(comp)
     assert len(camps) > 1
     ids = sorted([camp.campaign_id for camp in camps])
     ids2 = sorted([camp.campaign_id for camp in Campaign.load_ids(ids)])
     assert ids == ids2
Beispiel #5
0
 def search(self):
     name = self.request.POST.get('name')
     company_id = self.request.POST.get('company_id')
     return {
         'companies' : util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name'),
         'name' : name,
         'company_id' : company_id,
         'campaigns' : Campaign.search(self.enterprise_id, name, company_id)
     }
Beispiel #6
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 []
         }
Beispiel #7
0
def import_product_list(company_id, filename='/tmp/products/products.csv'):
    company = Company.load(company_id)
    default_campaign = company.default_campaign
    
    products = []
    with open(filename) as f:
        products = f.readlines()

    products = [p.rstrip() for p in products[1:]]

    product_categories = {}

    for pline in products:
        log(pline)
        (product_name, category_id, pic) = pline.split(',')
        pic = pic.strip()
        key = '%s%s' % (product_name.strip(), category_id.strip())
        cat = ProductCategory.load(category_id.strip(), False)
        prod = None
        if key in product_categories:
            prod = Product.load(product_categories[key][0], False)
        else:
            prod = Product()
            prod.company = company
            prod.name = product_name.strip()
            prod.type = 'Parent or Child'
            prod.save()
            prod.flush()
            product_categories[key] = [str(prod.product_id), str(cat.category_id)]

        ass = Asset()
        ass.fk_type = 'Product'
        ass.fk_id = prod.product_id
        ass.enterprise_id = company.enterprise_id
        ass.name = os.path.basename(pic)
        ass.extension = os.path.splitext(pic)[1]
        ass.save()
        ass.flush()        
        storage_root = Asset.get_storage_root()
        if not storage_root:
            storage_root = '/apps/pvs/storage'
        fs_real_dir = "{root}/{reldir}".format(root=storage_root, reldir=ass.relative_dir)
        util.mkdir_p(fs_real_dir)
        fs_real_path = "{fs_real_dir}/{assid}{ext}".format(fs_real_dir=fs_real_dir,
                                                           assid=ass.id,
                                                           ext=ass.extension)
        shutil.copyfile(pic, fs_real_path)

    for pc in product_categories:
        pcat = product_categories[pc]
        cat = ProductCategory.load(pcat[1], False)
        cat.add_product(pcat[0])

    db.commit()
Beispiel #8
0
 def _prep(self):
     charts = []
     # basic included snapshot reports.
     if self.request.ctx.user.priv.view_report:
         charts.append(PeriodOrderSummary(self.request))
         charts.append(MTDSalesByVendor(self.request))
         #charts.append(PeriodCustomerCountSummary(self.request))
     return {
         'companies': Company.find_all(self.request.ctx.enterprise.enterprise_id),
         'charts' : charts,
         'appointments' : Appointment.find_future_by_user(self.request.ctx.user)[:10]
         }
Beispiel #9
0
 def test_send_with_bad_attachment(self):
     ent = Enterprise.find_all()[0]
     comp = Company.find_all(ent.enterprise_id)[0]
     mail = UserMail(comp.default_campaign)
     rand_subj = random.random()
     excepted = False
     try:
         mail.send('*****@*****.**', 'test %s' % rand_subj,
                   'this should never make it.  bogus attachment.',
                   'BOGUS.txt')
     except IOError as ioe:
         excepted = True
     assert excepted
Beispiel #10
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}
Beispiel #11
0
 def _edit_impl(self):
     report_id = self.request.matchdict.get('report_id')
     report = None
     if report_id:
         report = Report.load(report_id)
         self.forbid_if(not report)
     else:
         report = Report()
     return {
         'report' : report,
         'reports' : Report.find_vendor_reports() if self.request.ctx.user.is_vendor_user() else Report.find_all(),
         'companies' : util.select_list(Company.find_all_all(), 'company_id', 'name')
         }
Beispiel #12
0
 def _edit_impl(self):
     company_id = self.request.matchdict.get('company_id')
     comms = []
     campaigns = util.select_list(Campaign.find_all(self.enterprise_id), 'campaign_id', 'name')
     company = None
     if company_id:
         company = Company.load(company_id)
         comms = util.select_list(Communication.find_all_by_company(company), 'comm_id', 'name')
     else:
         company = Company()
     return {'comms': comms,
             'company': company,
             'campaigns': campaigns}
Beispiel #13
0
 def _edit_impl(self):
     site_id = self.request.matchdict.get('site_id')
     self.session['last_site_id'] = site_id
     if site_id:
         site = Site.load(site_id)
         self.forbid_if(not site or str(site.company.enterprise_id) != str(self.enterprise_id))
     else:
         site = Site()
     return {
         'site' : site,
         'shipping_methods' : Site.get_shipping_methods(),
         'tax_methods' : Site.get_tax_methods(),
         'companies' : util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name'),
         'campaigns' : util.select_list(Campaign.find_all(self.enterprise_id), 'campaign_id', 'name')
         }
Beispiel #14
0
    def _edit_impl(self):
        campaign_id = self.request.matchdict.get('campaign_id')
        comms = []
        companies = util.select_list(Company.find_all(self.enterprise_id),
                                       'company_id', 'name')
        campaign = None
        if campaign_id:
            campaign = Campaign.load(campaign_id)
            self.forbid_if(not campaign or campaign.company.enterprise_id != self.enterprise_id)
            comms = util.select_list(Communication.find_all_by_company(campaign.company), 'comm_id', 'name', True)
        else:
            campaign = Campaign()

        return {'comms': comms,
                'campaign': campaign,
                'companies': companies}
Beispiel #15
0
 def _edit_impl(self):
     site_id = self.request.matchdict.get('site_id')
     site = Site.load(site_id)
     self.forbid_if(not site or str(site.company.enterprise_id) != str(self.enterprise_id))
     content_id = self.request.matchdict.get('content_id')
     if content_id:
         content = Content.load(content_id)
         self.forbid_if(not content
                        or str(content.site.company.enterprise_id) != str(self.enterprise_id)
                        or str(content.site_id) != str(site_id))
     else:
         content = Content()
         content.site_id = site_id
     return {
         'site' : site,
         'content' : content,
         'companies' : util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name'),
         'campaigns' : util.select_list(Campaign.find_all(self.enterprise_id), 'campaign_id', 'name')
         }
Beispiel #16
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
            }
Beispiel #17
0
    def provision(self):
        ent = Enterprise()
        ent.bind(self.request.POST, True, 'ent')
        ent.save()
        ent.flush()

        comp = Company()
        comp.bind(self.request.POST, True, 'cmp')
        comp.enterprise_id = ent.enterprise_id
        comp.save()
        comp.flush()

        campaign = Campaign()
        campaign.name = comp.name + ' Default'
        campaign.company_id = comp.company_id
        campaign.save()
        campaign.flush()

        comp.default_campaign_id = campaign.campaign_id
        comp.save()
        comp.flush()

        user = Users()
        user.bind(self.request.POST, True, 'u')
        user.password = Users.encode_password('password')
        user.enterprise_id = ent.enterprise_id
        user.type = 'Admin'
        user.save()
        user.flush()

        site = Site()
        site.bind(self.request.POST, True, 'st')
        site.company = comp
        site.description = comp.name + ' Site'
        site.creator = user
        #site.template = Template.find_by_name('default')
        site.save()
        site.flush()

        return {
            'enterprise' : ent,
            'company' : comp,
            'campaign' : campaign,
            'user' : user,
            'site' : site,
            'done' : True
            }
Beispiel #18
0
    def save(self):
        comp = Company.load(self.request.POST.get('company_id'))
        if not comp:
            comp = Company()
        comp.bind(self.request.POST)
        comp.save()
        comp.flush()
        #if not os.path.isdir(comp.web_full_directory):
        #    comp.create_dir_structure()
        comp.clear_attributes()
        for i in range(10):
            attr_name = self.request.POST.get('attr_name[%d]' % i)
            attr_value = self.request.POST.get('attr_value[%d]' % i)
            if attr_name and attr_value:
                comp.set_attr(attr_name, attr_value)

        self.request.session.flash('Successfully saved %s.' % comp.name)
        return HTTPFound('/crm/company/edit/%s' % comp.company_id)
Beispiel #19
0
 def list(self):
     return {'companies' : Company.find_all(self.enterprise_id)}
Beispiel #20
0
 def search(self):
     name = self.request.POST.get('name')
     return {'name' : name,
             'companies' :Company.search(name)}
Beispiel #21
0
 def invalidate_caches(self, **kwargs):
     if self.company_id:
         company = Company.load(self.company_id)
         if company:
             invalidate(self, 'Campaign.find_all', str(company.enterprise_id))    #pylint: disable-msg=E1101
Beispiel #22
0
 def _delete_new(self, company_id):
     comp = Company.load(company_id)
     self.assertNotEqual(comp, None)
     comp.delete()
     self.commit()