Beispiel #1
0
 def show_history(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)
     return {
         'history' : Status.find(purchase),
         'purchase' : purchase,
         'offset' : self.offset
         }
Beispiel #2
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 #3
0
 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)
Beispiel #4
0
 def search(self):
     vendor_id = self.request.POST.get('vendor_id') 
     from_dt = self.request.POST.get('from_dt', util.str_today())
     to_dt = self.request.POST.get('to_dt', util.str_today())
     return {
         'vendor_id' : vendor_id, 
         'from_dt' : from_dt, 
         'to_dt' : to_dt, 
         'purchases' : PurchaseOrder.search(self.enterprise_id, vendor_id, from_dt, to_dt),
         'vendors' : util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name')
         }
Beispiel #5
0
 def order_item_json(self):
     purchase_order_id = self.request.matchdict.get('purchase_order_id')
     order_item_id = self.request.matchdict.get('order_item_id')
     porder = PurchaseOrder.load(purchase_order_id)
     self.forbid_if(not porder)
     poi = PurchaseOrderItem.load(order_item_id)
     self.forbid_if(not poi or poi.purchase_order != porder)
     return json.dumps({'order_item_id':str(poi.order_item_id), 
                        'note':poi.note,
                        'quantity':poi.quantity, 
                        'unit_cost':poi.unit_cost,
                        'prod_name':poi.product.name})
Beispiel #6
0
 def save(self):
     porder = PurchaseOrder.load(self.request.POST.get('purchase_order_id'))
     new = False
     if not porder:
         new = True
         porder = PurchaseOrder()
     porder.bind(self.request.POST)
     porder.save()
     porder.flush()
     Status.add(None, porder, Status.find_event(self.enterprise_id, porder, 'CREATED' if new else 'MODIFIED'),
                'Purchase Order %s' % ('CREATED' if new else 'MODIFIED'),
                self.request.ctx.user)
     self.db_flush()
     self.flash('Successfully saved PO %s.' % porder.purchase_order_id)
     return HTTPFound('/crm/purchase/edit/%s' % porder.purchase_order_id)
Beispiel #7
0
 def complete(self):
     purchase_order_id = self.request.matchdict.get('purchase_order_id')
     porder = PurchaseOrder.load(purchase_order_id)
     self.forbid_if(not porder or porder.company.enterprise_id != self.enterprise_id)
     porder.complete_dt = util.today()
     porder.save()
     for oitem in porder.order_items:
         if not oitem.complete_dt:
             oitem.complete_dt = util.today()
             oitem.save()
             InventoryJournal.create_new(oitem.product, 'Item Receipt', oitem.quantity)
     Status.add(None, porder, Status.find_event(self.enterprise_id, porder, 'COMPLETED'),
                'Purchase Order Completed', self.request.ctx.user) 
     return 'True'
Beispiel #8
0
 def delete_purchase_order_item(self):
     purchase_order_id = self.request.matchdict.get('purchase_order_id')
     order_item_id = self.request.matchdict.get('order_item_id')
     porder = PurchaseOrder.load(purchase_order_id)
     self.forbid_if(not porder)
     poi = PurchaseOrderItem.load(order_item_id)
     self.forbid_if(not poi or poi.purchase_order != porder)
     prod = poi.product
     poi.delete()
     Status.add(None, porder, Status.find_event(self.enterprise_id, porder, 'MODIFIED'),
                'Purchase Order %s. "%s" removed.' % ('MODIFIED', prod.name),
                self.request.ctx.user)
     poi.flush()
     return 'True'
Beispiel #9
0
 def complete_item(self):
     purchase_order_id = self.request.matchdict.get('purchase_order_id')
     order_item_id = self.request.matchdict.get('order_item_id')
     porder = PurchaseOrder.load(purchase_order_id)
     self.forbid_if(not porder)
     poi = PurchaseOrderItem.load(order_item_id)
     self.forbid_if(not poi or poi.purchase_order != porder or poi.complete_dt)
     poi.complete_dt = util.today()
     poi.save()
     poi.flush()
     InventoryJournal.create_new(poi.product, 'Item Receipt', poi.quantity)
     Status.add(None, porder, Status.find_event(self.enterprise_id, porder, 'COMPLETED'),
                'Purchase Order Item "%s" Completed' % poi.product.name,
                self.request.ctx.user) 
     return 'True'
Beispiel #10
0
 def _delete_new(self, purchase_order_id):
     pord = PurchaseOrder.load(purchase_order_id)
     self.assertNotEqual(pord, None)
     pord.delete()
     self.commit()
Beispiel #11
0
 def list(self):
     return {'purchases' : PurchaseOrder.find_all_open(self.enterprise_id)}