コード例 #1
0
ファイル: product.py プロジェクト: hforge/shop
 def save_barcode(self, reference):
     shop = get_shop(self)
     format = shop.get_property('barcode_format')
     barcode = generate_barcode(format, reference)
     if not barcode:
         return
     self.del_resource('barcode', soft=True)
     metadata =  {'title': {'en': u'Barcode'},
                  'filename': 'barcode.png',
                  'format': 'image/png'}
     Image.make_resource(Image, self, 'barcode', body=barcode, **metadata)
コード例 #2
0
 def save_barcode(self, reference):
     shop = get_shop(self)
     format = shop.get_property('barcode_format')
     barcode = generate_barcode(format, reference)
     if not barcode:
         return
     self.del_resource('barcode', soft=True)
     metadata = {
         'title': {
             'en': u'Barcode'
         },
         'filename': 'barcode.png',
         'format': 'image/png'
     }
     Image.make_resource(Image, self, 'barcode', body=barcode, **metadata)
コード例 #3
0
ファイル: orders.py プロジェクト: nicolasderam/shop
 def _make_resource(cls, folder, name, *args, **kw):
     context = get_context()
     shop = kw['shop']
     user = kw['user']
     shop_uri = kw['shop_uri']
     cart = kw['cart']
     # Email
     user_email = user.get_property('email')
     # Build metadata/order
     metadata = {}
     for key in [
             'payment_mode', 'shipping_price', 'total_price', 'total_weight'
     ]:
         metadata[key] = kw[key]
     # Has tax ?
     id_zone = cart.id_zone
     zones = shop.get_resource('countries-zones').handler
     zone_record = zones.get_record(int(id_zone))
     has_tax = zones.get_record_value(zone_record, 'has_tax')
     # Addresses
     metadata['delivery_address'] = cart.addresses['delivery_address']
     metadata['bill_address'] = cart.addresses['bill_address'] or \
         cart.addresses['delivery_address']
     metadata['customer_id'] = user.name
     metadata['creation_datetime'] = datetime.now()
     metadata['shipping'] = cart.shipping
     ShopFolder._make_resource(cls, folder, name, *args, **metadata)
     # Save products
     handler = BaseOrdersProducts()
     for product_cart in cart.products:
         product = context.root.get_resource(product_cart['name'])
         declination = product_cart['declination']
         if has_tax:
             tax = TaxesEnumerate.get_value(product.get_property('tax'))
         else:
             tax = decimal(0)
         handler.add_record({
             'name':
             str(product.get_abspath()),
             'reference':
             product.get_reference(declination),
             'title':
             product.get_title(),
             'declination':
             declination,
             'pre-tax-price':
             product.get_price_without_tax(declination),
             'tax':
             tax,
             'weight':
             product.get_weight(declination),
             'quantity':
             product_cart['quantity']
         })
     metadata = OrdersProducts.build_metadata(title={'en': u'Products'})
     folder.set_handler('%s/products.metadata' % name, metadata)
     folder.set_handler('%s/products' % name, handler)
     # Get bill and delivery addresses
     addresses = shop.get_resource('addresses').handler
     delivery_record = addresses.get_record_kw(
         cart.addresses['delivery_address'])
     bill_record = addresses.get_record_kw(cart.addresses['bill_address']
                                           or 0)
     # Save addresses
     handler = BaseAddresses()
     handler.add_record(delivery_record)
     handler.add_record(bill_record)
     metadata = Addresses.build_metadata(title={'en': u'Addresses'})
     folder.set_handler('%s/addresses.metadata' % name, metadata)
     folder.set_handler('%s/addresses' % name, handler)
     # Add messages resource
     Messages_TableResource._make_resource(Messages_TableResource, folder,
                                           '%s/messages' % name,
                                           **{'title': {
                                               'en': u'Messages'
                                           }})
     # Generate barcode
     from shop.utils import generate_barcode
     order = shop.get_resource('orders/%s' % name)
     barcode = generate_barcode(shop.get_property('barcode_format'), name)
     metadata = {
         'title': {
             'en': u'Barcode'
         },
         'filename': 'barcode.png',
         'format': 'image/png'
     }
     Image.make_resource(Image, order, 'barcode', body=barcode, **metadata)
コード例 #4
0
ファイル: orders.py プロジェクト: hforge/shop
 def _make_resource(cls, folder, name, *args, **kw):
     context = get_context()
     shop = kw['shop']
     user = kw['user']
     shop_uri = kw['shop_uri']
     cart = kw['cart']
     # Email
     user_email = user.get_property('email')
     # Build metadata/order
     metadata = {}
     for key in ['payment_mode', 'shipping_price', 'total_price', 'total_weight']:
         metadata[key] = kw[key]
     # Has tax ?
     id_zone = cart.id_zone
     zones = shop.get_resource('countries-zones').handler
     zone_record = zones.get_record(int(id_zone))
     has_tax = zones.get_record_value(zone_record, 'has_tax')
     # Addresses
     metadata['delivery_address'] = cart.addresses['delivery_address']
     metadata['bill_address'] = cart.addresses['bill_address'] or \
         cart.addresses['delivery_address']
     metadata['customer_id'] = user.name
     metadata['creation_datetime'] = datetime.now()
     metadata['shipping'] = cart.shipping
     ShopFolder._make_resource(cls, folder, name, *args, **metadata)
     # Save products
     handler = BaseOrdersProducts()
     for product_cart in cart.products:
         product = context.root.get_resource(product_cart['name'])
         declination = product_cart['declination']
         if has_tax:
             tax = TaxesEnumerate.get_value(product.get_property('tax'))
         else:
             tax = decimal(0)
         handler.add_record(
           {'name': str(product.get_abspath()),
            'reference': product.get_reference(declination),
            'title': product.get_title(),
            'declination': declination,
            'pre-tax-price': product.get_price_without_tax(declination),
            'tax': tax,
            'weight': product.get_weight(declination),
            'quantity': product_cart['quantity']})
     metadata = OrdersProducts.build_metadata(title={'en': u'Products'})
     folder.set_handler('%s/products.metadata' % name, metadata)
     folder.set_handler('%s/products' % name, handler)
     # Get bill and delivery addresses
     addresses = shop.get_resource('addresses').handler
     delivery_record = addresses.get_record_kw(cart.addresses['delivery_address'])
     bill_record = addresses.get_record_kw(cart.addresses['bill_address'] or 0)
     # Save addresses
     handler = BaseAddresses()
     handler.add_record(delivery_record)
     handler.add_record(bill_record)
     metadata = Addresses.build_metadata(title={'en': u'Addresses'})
     folder.set_handler('%s/addresses.metadata' % name, metadata)
     folder.set_handler('%s/addresses' % name, handler)
     # Add messages resource
     Messages_TableResource._make_resource(Messages_TableResource, folder,
                             '%s/messages' % name,
                             **{'title': {'en': u'Messages'}})
     # Generate barcode
     from shop.utils import generate_barcode
     order = shop.get_resource('orders/%s' % name)
     barcode = generate_barcode(shop.get_property('barcode_format'), name)
     metadata =  {'title': {'en': u'Barcode'},
                  'filename': 'barcode.png',
                  'format': 'image/png'}
     Image.make_resource(Image, order, 'barcode', body=barcode, **metadata)