def status_dialog(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) order = order_item = events = redir = None if self.request.GET.get('order_id'): order = CustomerOrder.load(self.request.GET.get('order_id')) self.forbid_if(not order or order.campaign.company.enterprise_id != self.enterprise_id) events = util.select_list(StatusEvent.find_all_applicable(self.enterprise_id, order), 'event_id', 'display_name', True) redir = '/crm/customer/show_orders/%s' % customer_id elif self.request.GET.get('order_item_id'): order_item = OrderItem.load(self.request.GET.get('order_item_id')) self.forbid_if(not order_item or order_item.order.campaign.company.enterprise_id != self.enterprise_id) events = util.select_list(StatusEvent.find_all_applicable(self.enterprise_id, order_item), 'event_id', 'display_name', True) redir = '/crm/customer/edit_order_dialog/%s/%s' % (customer_id, order_item.order_id) else: events = util.select_list(StatusEvent.find_all_applicable(self.enterprise_id, customer), 'event_id', 'display_name', True) redir = '/crm/customer/edit/%s' % customer_id return { 'customer' : customer, 'order' : order, 'order_item' : order_item, 'events' : events, 'redir' : redir }
def _edit_impl(self): event_id = self.request.matchdict.get('event_id') event = None if event_id: event = StatusEvent.load(event_id) self.forbid_if(not event or event.enterprise_id != self.enterprise_id) else: event = StatusEvent() return { 'event' : event, 'event_types' : StatusEvent.get_status_types() }
def show_returns(self): product_id = self.request.matchdict['product_id'] product = Product.load(product_id) self.forbid_if(not product or product.company.enterprise_id != self.enterprise_id) return {'product' : product, 'events' : util.select_list(StatusEvent.find_all_applicable(self.enterprise_id, product), 'event_id', 'display_name'), 'returns' : ProductReturn.find(product)}
def save(self): evt = StatusEvent.load(self.request.POST.get('event_id')) if not evt: evt = StatusEvent() evt.enterprise_id = self.enterprise_id else: self.forbid_if(evt.enterprise_id != self.enterprise_id) evt.bind(self.request.POST, True) evt.save() evt.flush() self.flash('Successfully saved %s.' % evt.short_name) return HTTPFound('/crm/event/edit/%s' % evt.event_id)
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 show_purchases(self): product_id = self.request.matchdict['product_id'] from pvscore.model.crm.purchase import PurchaseOrderItem product = Product.load(product_id) self.forbid_if(not product or product.company.enterprise_id != self.enterprise_id) return {'product' : product, 'events' : util.select_list(StatusEvent.find_all_applicable(self.enterprise_id, product), 'event_id', 'display_name'), 'purchase_order_items' : PurchaseOrderItem.find_by_product(product) }
def save_status(self): product_id = self.request.POST['product_id'] product = Product.load(product_id) self.forbid_if(not product or product.company.enterprise_id != self.enterprise_id) event = StatusEvent.load(self.request.POST['event_id']) self.forbid_if(not event or (not event.is_system and event.enterprise_id != self.enterprise_id)) note = self.request.POST.get('note') Status.add(None, product, event, note, self.request.ctx.user) return HTTPFound('/crm/product/show_history/%s' % product_id)
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 _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 [] }
def test_save_status(self): ent = Enterprise.find_by_name('Healthy U Store') evt = StatusEvent.find(ent.enterprise_id, 'PurchaseOrder', 'TESTEVENT_PO') purchase_order_id = self._create_new() R = self.post(str('/crm/purchase/save_status/%s' % purchase_order_id), {'event_id' : evt.event_id, 'note' : 'Note Note'}) assert R.status_int == 200 self._delete_new(purchase_order_id)
def save_status(self): purchase_order_id = self.request.matchdict.get('purchase_order_id') purchase = PurchaseOrder.load(purchase_order_id) self.forbid_if(not purchase or purchase.company.enterprise_id != self.enterprise_id) event = StatusEvent.load(self.request.POST.get('event_id')) self.forbid_if(not event or not self.request.POST.get('event_id') or (not event.is_system and event.enterprise_id != self.enterprise_id)) note = self.request.POST.get('note') Status.add(None, purchase, event, note, self.request.ctx.user) self.flash("Saved status") return HTTPFound('/crm/purchase/edit/%s' % purchase_order_id)
def _test_save_status(self): ent = Enterprise.find_by_name('Healthy U Store') product_id = self._create_new() product = Product.load(product_id) events = StatusEvent.find_all_applicable(ent.enterprise_id, product) R = self.post('/crm/product/save_status', {'product_id': product_id, 'note' : 'Test Note %s' % product_id, 'event_id' : events[0].event_id}) assert R.status_int == 200 R.mustcontain('Product Event History') R.mustcontain('Test Note %s' % product_id) # assert that the edit page has the name of the event in green # at the top. R = self.get('/crm/product/edit/%s' % product_id) assert R.status_int == 200 R.mustcontain('Edit Product') R.mustcontain(events[0].short_name) self._delete_new(product_id)
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 }
def save_status(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) event = StatusEvent.load(self.request.POST.get('event_id')) self.forbid_if(not event or not self.request.POST.get('event_id') or (not event.is_system and event.enterprise_id is not None and event.enterprise_id != self.enterprise_id)) order = None note = self.request.POST.get('note') if self.request.POST.get('order_id'): order = CustomerOrder.load(self.request.POST.get('order_id')) self.forbid_if(not order or order.campaign.company.enterprise_id != self.enterprise_id) Status.add(customer, order, event, note, self.request.ctx.user) self.flash('Statused Order to %s' % event.display_name) elif self.request.POST.get('order_item_id'): order_item = OrderItem.load(self.request.POST.get('order_item_id')) self.forbid_if(not order_item or order_item.order.campaign.company.enterprise_id != self.enterprise_id) Status.add(customer, order_item, event, note, self.request.ctx.user) self.flash('Statused Item to %s' % event.display_name) else: Status.add(customer, customer, event, note, self.request.ctx.user) self.flash('Statused Customer to %s' % event.display_name) customer.invalidate_caches() return self.find_redirect()
def find_event(enterprise_id, obj, short_name): return StatusEvent.find(enterprise_id, type(obj).__name__, short_name)
def list(self): return {'events' : StatusEvent.find_all(self.enterprise_id)}
def _delete_new(self, event_id): StatusEvent.full_delete(event_id) self.commit()