示例#1
0
文件: orders.py 项目: hforge/itws
 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)
示例#2
0
文件: shop_views.py 项目: hforge/shop
 def action_pay(self, resource, context, form):
     from orders import Order
     cart = ProductCart(context)
     root = context.root
     # Check if cart is valid
     if not cart.is_valid():
         return context.come_back(CART_ERROR, goto='/')
     # Calcul total price
     total_price_with_tax = decimal(0)
     total_price_without_tax = decimal(0)
     total_weight = decimal(0)
     for cart_elt in cart.products:
         product = context.root.get_resource(cart_elt['name'])
         quantity = cart_elt['quantity']
         declination = cart_elt['declination']
         unit_price_with_tax = product.get_price_with_tax(declination)
         unit_price_without_tax = product.get_price_without_tax(declination)
         total_price_with_tax += unit_price_with_tax * quantity
         total_price_without_tax += unit_price_without_tax * quantity
         total_weight += product.get_weight(declination) * quantity
     # Get Shipping price
     shipping_price = cart.get_shipping_ns(resource, context)['price']
     total_price_with_tax += shipping_price
     total_price_without_tax += shipping_price
     # Arrondi
     total_price_with_tax = get_arrondi(total_price_with_tax)
     total_price_without_tax = get_arrondi(total_price_without_tax)
     # Guess ref number
     # We take last order name + 1
     search = root.search(format='order')
     orders =  search.get_documents(sort_by='creation_datetime',
                                    reverse=True)
     if orders:
         ref = str(int(orders[0].name) + 1)
     else:
         ref = '1'
     # We create a new order
     kw = {'user': context.user,
           'payment_mode': form['payment'],
           'shipping_price': shipping_price,
           'total_price': total_price_with_tax,
           'total_weight': total_weight,
           'cart': cart,
           'shop': resource,
           'shop_uri': context.uri.resolve('/')}
     orders = resource.get_resource('orders')
     order = Order.make_resource(Order, orders, ref,
                         title={'en': u'#%s' % ref},
                         **kw)
     # We clear the cart
     cart.clear()
     # We show the payment form
     kw = {'ref': ref,
           'amount': total_price_with_tax,
           'amount_without_tax': total_price_without_tax,
           'resource_validator': str(order.get_abspath()),
           'mode': form['payment']}
     payments = resource.get_resource('payments')
     return payments.show_payment_form(context, kw)
示例#3
0
文件: product.py 项目: hforge/itws
 def get_price_with_tax(self, with_devise=False):
     price = self.get_property('pre_tax_price')
     tax = self.get_tax_value() / decimal(100) + 1
     price = get_arrondi(price * tax)
     if with_devise is False:
         return price
     return format_price(price)
示例#4
0
文件: orders.py 项目: hforge/itws
 def get_products_namespace(self, context):
     root = context.root
     query = AndQuery(
         get_base_path_query(self.get_canonical_path()),
         PhraseQuery('format', 'order-product'))
     l = []
     for brain in root.search(query).get_documents():
         resource = root.get_resource(brain.abspath, soft=True)
         if resource is None:
             log_warning('ORDER-PRODUCT not found : %s' % brain.abspath)
             continue
         # Get base product namespace
         kw = {}
         for key in ['reference', 'title', 'tax', 'quantity']:
             kw[key] = resource.get_property(key)
         kw['pre_tax_price'] = resource.get_property('pre_tax_price')
         tax = kw['tax'] / decimal(100) + 1
         kw['price_with_tax'] = get_arrondi(kw['pre_tax_price'] * tax)
         total_price = kw['price_with_tax'] * kw['quantity']
         kw['pre_tax_price'] = self.format_price(kw['pre_tax_price'])
         kw['total_price'] = self.format_price(total_price)
         kw['price_with_tax'] = self.format_price(kw['price_with_tax'])
         # Get product link (if exist)
         abspath = resource.get_property('abspath')
         product = root.get_resource(abspath, soft=True)
         if product:
             # Add link only if edit allowed
             link = None
             ac = resource.get_access_control()
             if ac.is_allowed_to_edit(context.user, product):
                 link = context.get_link(product)
             kw['link'] = link
         # Add product to list of products
         l.append(kw)
     return l
示例#5
0
 def get_csv_value(self, resource, context, item, column):
     brain, item_resource = item
     if column == 'name':
         return brain.name
     elif column == 'customer_id':
         return item_resource.get_property('customer_id')
     elif column == 'workflow_state':
         value = item_resource.get_statename()
         title = OrderStateEnumerate.get_value(value)
         return title.gettext()
     elif column in ('total_price', 'total_paid'):
         value = item_resource.get_property(column)
         return value
     elif column in ('total_pre_vat', 'total_vat'):
         total_pre_vat, total_vat = item_resource.get_vat_details(context)
         return get_arrondi(eval(column))
     elif column in ('ctime',):
         value = brain.ctime
         return context.format_datetime(value)
     return ''
示例#6
0
 def action_pay(self, resource, context, form):
     from orders import Order
     cart = ProductCart(context)
     root = context.root
     # Check if cart is valid
     if not cart.is_valid():
         return context.come_back(CART_ERROR, goto='/')
     # Calcul total price
     total_price_with_tax = decimal(0)
     total_price_without_tax = decimal(0)
     total_weight = decimal(0)
     for cart_elt in cart.products:
         product = context.root.get_resource(cart_elt['name'])
         quantity = cart_elt['quantity']
         declination = cart_elt['declination']
         unit_price_with_tax = product.get_price_with_tax(declination)
         unit_price_without_tax = product.get_price_without_tax(declination)
         total_price_with_tax += unit_price_with_tax * quantity
         total_price_without_tax += unit_price_without_tax * quantity
         total_weight += product.get_weight(declination) * quantity
     # Get Shipping price
     shipping_price = cart.get_shipping_ns(resource, context)['price']
     total_price_with_tax += shipping_price
     total_price_without_tax += shipping_price
     # Arrondi
     total_price_with_tax = get_arrondi(total_price_with_tax)
     total_price_without_tax = get_arrondi(total_price_without_tax)
     # Guess ref number
     # We take last order name + 1
     search = root.search(format='order')
     orders = search.get_documents(sort_by='creation_datetime',
                                   reverse=True)
     if orders:
         ref = str(int(orders[0].name) + 1)
     else:
         ref = '1'
     # We create a new order
     kw = {
         'user': context.user,
         'payment_mode': form['payment'],
         'shipping_price': shipping_price,
         'total_price': total_price_with_tax,
         'total_weight': total_weight,
         'cart': cart,
         'shop': resource,
         'shop_uri': context.uri.resolve('/')
     }
     orders = resource.get_resource('orders')
     order = Order.make_resource(Order,
                                 orders,
                                 ref,
                                 title={'en': u'#%s' % ref},
                                 **kw)
     # We clear the cart
     cart.clear()
     # We show the payment form
     kw = {
         'ref': ref,
         'amount': total_price_with_tax,
         'amount_without_tax': total_price_without_tax,
         'resource_validator': str(order.get_abspath()),
         'mode': form['payment']
     }
     payments = resource.get_resource('payments')
     return payments.show_payment_form(context, kw)
示例#7
0
文件: product.py 项目: hforge/itws
 def get_price_without_tax(self, with_devise=False):
     price = get_arrondi(self.get_property('pre_tax_price'))
     if with_devise is False:
         return price
     return format_price(price)