def generate_bill(self, context): """Creates bill as a pdf.""" # Get template document = self.get_resource('/ui/shop/orders/bill.xml') # Build namespace orders = get_orders(self) namespace = self.get_namespace(context) namespace['logo'] = orders.get_pdf_logo_key(context) signature = orders.get_property('signature') signature = signature.encode('utf-8') namespace['pdf_signature'] = XMLParser(signature.replace('\n', '<br/>')) # Products namespace['products'] = self.get_products_namespace(context) # Company company = orders.get_property('company') company = company.encode('utf-8') namespace['pdf_company'] = XMLParser(company.replace('\n', '<br/>')) # Customer namespace['customer'] = self.get_customer_namespace(context) # VAT total_pre_vat, total_vat = self.get_vat_details(context) total_pre_vat = self.format_price(get_arrondi(total_pre_vat)) total_vat = self.format_price(get_arrondi(total_vat)) namespace['total_pre_vat'] = total_pre_vat namespace['total_vat'] = total_vat # Build pdf try: pdf = stl_pmltopdf(document, namespace=namespace) except Exception: return None title = MSG(u'Bill').gettext() name = checkid(title) metadata = {'title': {'en': title}, 'filename': '%s.pdf' % name} self.del_resource(name, soft=True) return self.make_resource(name, PDF, body=pdf, **metadata)
def get_namespace(self, resource, context): orders = get_orders(resource) namespace = resource.get_namespace(context) namespace['orders_link'] = context.get_link(orders) namespace['order'] = {'id': resource.name} #namespace['state'] = SelectWidget('state', has_empty_option=False, # datatype=OrderStateEnumerate, value=resource.get_statename()).render() return namespace
test_prefix = prefix + 'test_set_1/' cluster2id, id2cluster = utils.get_cluster_map(test_prefix + 'cluster_map/cluster_map') dates, time_idx, dests = 21, 288, 66 train_orders_dest = np.zeros((dates, time_idx, dests, 67), dtype=np.float32) # 去向地 train_orders_price = np.zeros((dates, time_idx, dests, 67), dtype=np.float32) # 价格 train_orders_gap = np.zeros((dates, time_idx, dests), dtype=np.float32) # gap train_weathers = np.zeros((dates, time_idx, 3), dtype=np.float32) train_traffics = np.zeros((dates, time_idx, dests, 4), dtype=np.float32) for idx, date in enumerate(range(1, 22)): print('date {0:0>2}'.format(date)) order = utils.get_orders( train_prefix + 'order_data/order_data_2016-01-{0:0>2}'.format(date)) order = order.loc[:, [ 'driver_id', 'start_id', 'dest_id', 'price', 'time_idx' ]] order['start_id'] = order['start_id'].map(lambda x: cluster2id[x]) order['dest_id'] = order['dest_id'].map(lambda x: cluster2id[x] if x in cluster2id.keys() else 0) dest = np.zeros((time_idx, dests, 67), dtype=np.float32) price = np.zeros((time_idx, dests, 67), dtype=np.float32) gap = np.price = np.zeros((time_idx, dests), dtype=np.float32) for i in range(order.shape[0]): t = order.iloc[i] if t['driver_id'] == 'nan': gap[t['time_idx'], t['start_id'] - 1] += 1 else:
from utils import get_orders, mod, gcd def find_period(a, x, n): start = mod(a, x, n) for r in range(1, 100): temp = mod(a, x + r, n) if start == temp: # print(f"{a} ^ {x} = {a} ^ {x + r}") return r factors = get_orders(77) print(factors) for a in factors: r = find_period(a, 1, 77) if r % 2 == 1: continue temp = mod(a, r / 2, 77) if temp == (-1 % 77): continue print(f"a = {a}, r = {r}") x = gcd(a**(r / 2) + 1, 77) y = gcd(a**(r / 2) - 1, 77) print(x, y)
def order(df): return len(df) - df.apply(lambda x: get_orders(x), axis=0)
def action(self, resource, context, form): orders_module = get_orders(resource) order = orders_module.make_order(resource, context.user, lines=[]) goto = context.get_link(order) message = MSG(u'Order has been created') return context.come_back(message, goto=goto)