def _remember_campaign(request): if 'campaign_id' in request.session: request.ctx.campaign = Campaign.load(request.session['campaign_id']) else: if '__cid' in request.params: request.ctx.campaign = Campaign.load(request.params['__cid']) else: if request.ctx.site: request.ctx.campaign = Campaign.load(request.ctx.site.company.default_campaign_id) request.session['campaign_id'] = request.ctx.campaign.campaign_id
def _create_new(self): R = self.get('/crm/campaign/new') assert R.status_int == 200 R.mustcontain('Edit Campaign') f = R.forms['frm_campaign'] self.assertEqual(f['campaign_id'].value, '') f.set('name', 'Test Campaign') f.set('default_url', 'testxyz.com') f.set('email', '*****@*****.**') f.set('smtp_username', 'suser') f.set('smtp_password', 'spass') f.set('smtp_server', 'sserver') f.set('imap_username', 'imapuser') f.set('imap_password', 'imappass') f.set('imap_server', 'imapserver') f.set('attr_name[0]', 'attr0key') f.set('attr_value[0]', 'attr0val') f.set('attr_name[1]', 'attr1key') f.set('attr_value[1]', 'attr1val') R = f.submit('submit') self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms['frm_campaign'] R.mustcontain('Edit Campaign') campaign_id = f['campaign_id'].value self.assertNotEqual(f['campaign_id'].value, '') cmpn = Campaign.load(campaign_id) assert cmpn is not None assert cmpn.get_email_info() is not None return campaign_id
def save_inventory(self): prod = Product.load(self.request.POST.get('id')) self.forbid_if(not prod or prod.company.enterprise_id != self.enterprise_id) InventoryJournal.create_new(prod, 'Inventory Adjust', float(self.request.POST.get('inventory', 0))) prod.name = self.request.POST.get('name') prod.manufacturer = self.request.POST.get('manufacturer') prod.unit_cost = util.nvl(self.request.POST.get('unit_cost'), 0.0) prod.sku = self.request.POST.get('sku') prod.inventory_par = util.nvl(self.request.POST.get('inventory_par'), None) prod.save() # save all the prices, prefixed by "cmp_" for k in self.request.POST.keys(): if k.startswith('cmp_'): match = re.search(r'^.*_(.*)', k) if match: campaign = Campaign.load(match.group(1)) price = self.request.POST.get(k) if price: price = util.float_(price) prod.set_price_only(campaign, price) else: prod.remove_price(campaign) prod.invalidate_caches(campaign_id=campaign.campaign_id) return 'True'
def test_single_search(self): campaign_id = self._create_new() camp = Campaign.load(campaign_id) R = self.post('/crm/campaign/search', {'name': 'Test Campaign', 'company_id' : camp.company_id}) R.mustcontain('%s : Test Campaign' % campaign_id) self._delete_new(campaign_id)
def test_create_new(self): listing_id = self._create_new() cust = Customer.find(TEST_CUSTOMER_EMAIL, Campaign.load(self.site.default_campaign_id)) listings = Listing.find_by_customer(cust) assert len(listings) == 1 assert str(listings[0].listing_id) == listing_id Listing.find_last_n_assets(10) self._delete_new(listing_id)
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}
def _site_purchase(self, cust, cart=None): #pylint: disable-msg=R0912,R0915 """ KB: [2013-02-20]: MOD ATTR CustomerController._site_purchase : Allow for attributes passed in the post """ bill = self._create_billing(cust) campaign = Campaign.load(cust.campaign_id) if not cart: cart = Cart() product_skus = self.request.POST.getall('product_sku') for sku in product_skus: prod = Product.find_by_sku(self.enterprise_id, campaign, sku) if prod: cart.add_item(product=prod, campaign=cust.campaign, start_dt=self.request.POST.get('bill_start_dt') ) else: self.flash("No such product sku: %s" % sku) self.raise_redirect(self.request.referrer) order = cust.add_order(cart, None, self.enterprise_id, campaign, order_note=self.request.POST.get('order_note')) return self._bill_credit_card(cust, order, bill)
def save(self): cmpn = Campaign.load(self.request.POST.get('campaign_id')) if not cmpn: cmpn = Campaign() else: self.forbid_if(cmpn.company.enterprise_id != self.enterprise_id) cmpn.bind(self.request.POST) cmpn.save() cmpn.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: cmpn.set_attr(attr_name, attr_value) cmpn.save() cmpn.flush() cmpn.invalidate_self() cmpn.invalidate_caches() self.request.session.flash('Successfully saved %s.' % cmpn.name) return HTTPFound('/crm/campaign/edit/%s' % cmpn.campaign_id)
def _delete_new(self, campaign_id): camp = Campaign.load(campaign_id) self.assertNotEqual(camp, None) camp.delete() self.commit()
def save(self): #pylint: disable-msg=R0912,R0915 product_id = self.request.POST.get('product_id') if product_id: prod = Product.load(product_id) else: prod = Product() prod.bind(self.request.POST, True) prod.mod_dt = util.now() prod.save() self.db_flush() new_children = {} for k in self.request.POST.keys(): if k.startswith('campaign_price'): match = re.search(r'^.*\[(.*)\]', k) if match: campaign = Campaign.load(match.group(1)) price = self.request.POST.get(k) discount = self.request.POST.get('campaign_discount[%s]' % campaign.campaign_id) if price: price = util.float_(price) discount = util.float_(util.nvl(discount, 0.0)) prod.set_price(campaign, price, discount) else: prod.remove_price(campaign) if k.startswith('child_incl'): child_product_id = self.request.POST.get(k) child_product_quantity = self.request.POST.get('child_quantity_%s' % child_product_id) new_children[child_product_id] = child_product_quantity # KB: [2013-02-23]: Clear out old children that were just deselected and add the ones that are still selected. for current_child in prod.get_children(): if current_child.child_id not in new_children.keys(): prod.clear_child(current_child.child_id) for new_child_product_id in new_children.keys(): new_child_product_quantity = new_children[new_child_product_id] prod.add_child(new_child_product_id, new_child_product_quantity) prod.save() self.db_flush() redir_params = '' if 'parent_id' in self.request.POST and self.request.POST['parent_id']: parent = Product.load(self.request.POST['parent_id']) if not parent.has_child(prod.product_id): parent.add_child(prod.product_id) parent.save() redir_params = '?is_attribute=True&parent_id=%s' % parent.product_id inventory = str(self.request.POST.get('prod_inventory', '0')) if inventory and str(round(float(inventory), 2)) != str(round(util.nvl(InventoryJournal.total(prod), 0), 2)): InventoryJournal.create_new(prod, 'Inventory Adjust', inventory) self.db_flush() self.flash('Inventory Adjusted to %s' % inventory) prod.clear_attributes() for i in range(30): 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: prod.set_attr(attr_name, attr_value) category_id = self.request.POST.get('category_id') if category_id: category = ProductCategory.load(category_id) self.forbid_if(not category) category.add_product(prod.product_id) self.flash('Successfully saved %s.' % prod.name) return HTTPFound('/crm/product/edit/%s%s' % (prod.product_id, redir_params))