示例#1
0
 def assignFields(self, order_list):
     """Assign the fields collected to the order dict expected by the report
     and append that to the list passed in."""
     order_list.append(
         {"foid": self.order.order_id,
          "vip": self.vip,
          "book_id": self.product_item_id,
          "batch_id": self.batch_id,
          "order_number": self.order_number,
          "orig_order_num": self.original_order_number,
          "order_state": self.order_state,
          "batch_state": self.batch_state,
          "mfg_state": self.mfg_state,
          "show_mfg_state": self.show_mfg_state,
          "show_batch_state": self.show_batch_state,
          "before_coupon": "%0.2f" % self.gross,
          "gross": "%0.2f" % self.net, # yes it seems wrong but it's not
          "tax": "%0.2f" % self.tax,
          "discount": "%0.2f" % (self.gross - self.net),
          "order_total": "%0.2f" % self.order_total,
          "cc_paid": "%0.2f" % self.cc_paid,
          "order_date": self.order_date,
          "date": self.date,
          "ship_date": self.ship_date,
          "ship_dates": self.ship_dates,
          "partner": self.partner,
          "promo": self.promo,
          "coupon_code": self.coupon_code,
          "assoc": self.assoc,
          "shipping": "%0.2f" % self.shipping,
          "fee": "%0.2f" % self.fee,
          "ship_to": self.ship_to,
          "ship_address": self.ship_address,
          "ship_city": self.ship_city,
          "ship_state": self.ship_state,
          "ship_zip": self.ship_zip,
          "ship_country": self.ship_country,
          "ship_phone": self.ship_phone,
          "method": self.method,
          "method_link": self.method_link,
          "method_title": self.method_title,
          "bill_to": self.bill_to,
          "bill_address": self.bill_address,
          "bill_city": self.bill_city,
          "bill_state": self.bill_state,
          "bill_zip": self.bill_zip,
          "bill_country": self.bill_country,
          "bill_phone": self.bill_phone,
          "bill_email": self.bill_email,
          "product": self.product, 
          "simplex_duplex": self.simplex_duplex, 
          "qty": self.qty, 
          "pages": self.pages, 
          "cover_color": until(self.cover_color, "_"),
          "leather": self.leather,
          "orientation": self.orientation,
          "tracking_number": self.tracking_number,
          "tracking_numbers": self.tracking_numbers,
          "custom_info": self.theme,
          "currency": self.currency,
          "comments": self.comments,
          "verisign": self.dc_transaction_number,
          "dc_transaction_number": self.dc_transaction_number,
          "charge_date": self.charge_date,
          "cover_thumb": self.cover_thumb,
          "pdf": self.pdf_url,
          "dime_url": self.dime_url,
          "client": self.version,            
          "payment_processor": self.payment_processor,
          "user_id": self.order.customer.username,
          "refunds": self.refunds,
          "product_group": self.product_group,
          "return_address": self.return_address,
          "recipient": self.recipient,
          "recipient_email": self.recipient_email,
          "redeemed_orders": self.redeemed_orders,
          "gc_code": self.gc_code,
          "gc_amount": "%0.2f" % self.gc_amount,
          "gc_amount_redeemed": "%0.2f" % self.gc_amount_redeemed,
          "gc_balance": "%0.2f" % self.gc_balance,
          "gift_certs": self.gift_certs})
示例#2
0
    def getFilters(self, params):
        '''Translate parameters into sqlalchemy filter conditions'''

        filters = params.get('filters', [])
        if isinstance(filters, str):
            filters = filters.split(';')
        try:
            start_date = Date([params.startYear, params.startMon, 
                               params.startDay])
        except:
            start_date = None
        try:
            end_date = Date([params.endYear, params.endMon, params.endDay])
        except:
            end_date = Date()
        if 'start_date' in params:
            start_date = Date(params.start_date)
        if 'end_date' in params:
            end_date = Date(params.end_date)
        #start_date = Date('2009-11-11')
        #end_date = Date('2009-11-20')
        if start_date:
            params.drange = '%s - %s' % (start_date.format('%B %d, %Y'),
                                         end_date.format('%B %d, %Y'))
            end_date += 1   # to account for hours/min/sec 
            params.date_span = end_date - start_date
            if 'dtype' not in params or params.dtype == 'order_date':
                dtype = 'o.order_date'
            elif params.dtype == 'charge_date':
                dtype = 'pay.payment_date'
            elif params.dtype == 'ship_date':
                dtype = 'i.ship_date'
            elif params.dtype == 'cancel_date':
                dtype = 'can.history_date'
            # if row dim is order_date, use dtype instead
            for i, d in enumerate(params.dims):
                params.dims[i][0] = d[0].replace('order_date',
                                                 params.dtype)
            filters += ["%s >= '%s'" % (dtype, start_date.to_dt()),
                        "%s < '%s'"  % (dtype, end_date.to_dt())]
        else:
            filters += ['wi.state_id < 500']
        if 'cover_material' in params:
            filters += ["cm.code == '%s'" % params.cover_material]
        if 'product' in params:
            filters += ["p.code == '%s'" % params.product]
        if 'client' in params:
            filters += ["sc.code == '%s'" % params.client]
        if 'product_type' in params:
            filters += ["pt.code == '%s'" % params.product_type]
        if 'country' in params:
            if params.country == 'US':
                filters += ["a.country == 'US'"]
            elif params.country == 'UK/EU':
                filters += ["a.country <> 'US'"]
        if params.get('partner') not in ('All', None):
            filters += ["par.name == '%s'" % params.partner]
        # <A>_per_order -> <A>_per_<unit|page>
        if 'avetype' in params and params.avetype <> 'per_order':   
            extra = []
            for e in params.extra_cols:
                if '_per_' not in e or e.endswith(params.avetype) or \
                   e.startswith(params.avetype[4:] + 's'):
                    extra.append(e)
                else:
                    new = until(e, 'per_') +  params.avetype
                    if new <> 'units_per_page': # remove this silly fact
                        extra.append(until(e, 'per_') +  params.avetype)
            params.extra_cols = extra
        return filters