def get_location(cls,entity=None,case=None): from courtrecords.models import Entities, Cases id = 0 if entity: e = Entities.load(id=entity) case = e.case_id if case: c = Cases.load(id=case) id = c.archive if id: return Archives.load(id=id) return None
def create_invoice(self): records = self.request.params.getall('records') if records: fullname = self.request.params.get('customer.name','') email = self.request.params.get('customer.email','') address = self.request.params.get('customer.address','') address2 = self.request.params.get('customer.address2','') phone = self.request.params.get('customer.phone','') agreement = Validators.bool(self.request.params.get('customer.agreement',0)) checkout = self.request.params.getall('customer.checkout') deliver_digitally = False deliver_physically = False # Delivery Options for option in checkout: if option == 'digitally': deliver_digitally = True if option == 'physically': deliver_physically = True # Prep Orders orders = [] total_price = 0.0 location_emails = {} # to notify any locations a request has been made for record in records: c = Cases.load(id=int(record)) e = Entities.load(case_id=int(record)) r = Roles.load(id=e.role) l = Archives.load(id=c.archive) location_emails[l.email] = l.email total_price += float(r.price) orders.append({'case':int(c.id), 'price' : r.price, 'location':int(l.id)}) invoice = Invoices(fullname=fullname, email=email, address=address, county_state_zip=address2, phone=phone, records=orders, agreement_accepted=agreement, deliver_digitally=deliver_digitally, deliver_physically=deliver_physically, total_price='${:,.2f}'.format(total_price)) invoice.insert(self.request) invoice = Invoices.load(order='id desc') #Email Client starting_status = Statuses.load(order='priority asc') Emailer.send(self.request, [email], starting_status.email_subject, starting_status.email_message, link=self.request.application_url + '/invoice/' + invoice.hash ) #Email Archives Involved Emailer.send(self.request, list(location_emails), 'Order request has been placed', 'A new order request has been placed', link=self.request.application_url + '/login?goto=' + self.request.application_url + '/manage/orders' ) response = HTTPFound(location=route_url('invoice', self.request, hash=invoice.hash)) response.delete_cookie('basket') return response else: return self.response
def _save(self, case_id): entities, new_entities = {}, {} cases, new_cases = {}, {} for k,v in self.request.params.items(): action, table, attr, id = k.split('.') if action == 'edit': if table == 'Entities': if id not in entities: entities[id] = { attr : v } else: entities[id][attr] = v if table == 'Cases': if id not in cases: cases[id] = { attr : v } else: cases[id][attr] = v if action == 'new': if table == 'Entities': if id not in new_entities: new_entities[id] = { attr : v } else: new_entities[id][attr] = v if table == 'Cases': if id not in new_cases: new_cases[id] = { attr : v } else: new_cases[id][attr] = v #new_cases[id]['year'] = self._determine_year # save new cases for k,v in new_cases.items(): case = Cases() for attr,value in v.items(): setattr(case,attr,value) case.year = self._determine_year(case.year_text)[0] case_id = case.insert(self.request) # save new entities for k,v in new_entities.items(): entity = Entities() for attr,value in v.items(): setattr(entity,attr,value) entity.case_id = case_id entity.insert(self.request) # save existing cases for k,v in cases.items(): case = Cases.load(id=k) for attr,value in v.items(): setattr(case,attr,value) case.year = self._determine_year(case.year_text)[0] case.save(self.request) # save existing entities for k,v in entities.items(): entity = Entities.load(id=k) for attr,value in v.items(): setattr(entity,attr,value) entity.save(self.request)