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'
def delete(self): customer_id = self.request.matchdict.get('customer_id') customer = Customer.load(customer_id) self.forbid_if(not customer or customer.campaign.company.enterprise_id != self.enterprise_id) customer.mod_dt = util.now() customer.delete_dt = util.now() Status.add(customer, customer, StatusEvent.find(self.enterprise_id, 'Customer', 'DELETED'), 'Customer Deleted') return 'True'
def delete(self): product_id = self.request.matchdict.get('product_id') product = Product.load(product_id) self.forbid_if(not product or str(product.company.enterprise_id) != str(self.enterprise_id)) product.mod_dt = util.now() product.delete_dt = util.now() Status.add(None, product, StatusEvent.find(self.enterprise_id, 'Product', 'DELETED'), 'Product Deleted') product.invalidate_caches() return 'True'
def emit(self, record): """ Emit a record. Format the record and send it to the specified addressees. """ try: port = self.mailport if self.mailport else smtplib.SMTP_PORT smtp = smtplib.SMTP(self.mailhost, port) msg = self.format(record) msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % ( self.fromaddr, ",".join(self.toaddrs), self.getSubject(record), util.now(), msg) if self.username: smtp.ehlo() smtp.starttls() smtp.ehlo() smtp.login(self.username, self.password) smtp.sendmail(self.fromaddr, self.toaddrs, msg) smtp.quit() except (KeyboardInterrupt, SystemExit): #pragma: no cover raise except: #pragma: no cover self.handleError(record)
def find_by_code(enterprise_id, code): return Session.query(Discount)\ .filter(and_(Discount.enterprise_id == enterprise_id, Discount.delete_dt == None, Discount.code.ilike(code), or_(Discount.end_dt == None, Discount.end_dt >= util.now())))\ .order_by(Discount.create_dt) \ .first()
def find_all_active(enterprise_id, web_enabled=True): return Session.query(Discount) \ .filter(and_(Discount.delete_dt == None, Discount.enterprise_id == enterprise_id, Discount.web_enabled == web_enabled, or_(Discount.end_dt == None, Discount.end_dt >= util.now())))\ .order_by(Discount.name) \ .all()
def find_all_automatic_cart_discounts(enterprise_id, web_enabled=True): #pylint: disable-msg=C0103 return Session.query(Discount) \ .filter(and_(Discount.delete_dt == None, Discount.enterprise_id == enterprise_id, Discount.cart_discount == True, Discount.automatic == True, Discount.web_enabled == web_enabled, or_(Discount.end_dt == None, Discount.end_dt >= util.now())))\ .order_by(Discount.name) \ .all()
def render(self, customer, order, extra_message=None): ret = '' if self.data: if 'html' == self.type: dat = self.data dat = dat.replace('{message}', util.nvl(extra_message, '')) dat = dat.replace('{current_date}', util.words_date(util.now())) dat = self.tokenize(dat, customer, order) for otok in self._other_tokens.keys(): dat = dat.replace(otok, self._other_tokens[otok]) ret = literal(dat) return ret
def find_public(enterprise_id): return ( Session.query(Appointment) .join((Users, Appointment.user_created == Users.user_id)) .filter( and_( Appointment.public == True, Appointment.delete_dt == None, Users.enterprise_id == enterprise_id, Appointment.start_dt >= util.now(), ) ) .order_by(Appointment.start_dt.desc(), Appointment.start_time.asc()) .all() )
def save(self): pcat = ProductCategory.load(self.request.POST.get('category_id')) if not pcat: pcat = ProductCategory() pcat.bind(self.request.POST) pcat.mod_dt = util.now() pcat.save() pcat.flush() pcat.clear_products() pcat.flush() for k in self.request.POST.keys(): if k.startswith('child_incl'): child_product_id = self.request.POST.get(k) pcat.add_product(child_product_id) pcat.flush() pcat.invalidate_caches() self.request.session.flash('Successfully saved %s.' % pcat.name) return HTTPFound('/crm/product/category/edit/%s' % pcat.category_id)
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))