Exemple #1
0
 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
         }
Exemple #2
0
 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)}
Exemple #3
0
 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)
             }
Exemple #4
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 []
         }
Exemple #5
0
 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)
Exemple #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
            }