Exemplo n.º 1
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)
Exemplo n.º 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)
Exemplo n.º 3
0
 def _make_resource(cls, folder, name, *args, **kw):
     ShopFolder._make_resource(cls, folder, name, *args, **kw)
     # Image
     body = lfs.open(get_abspath(cls.img)).read()
     img = Image._make_resource(Image, folder,
                                '%s/logo.png' % name, body=body,
                                **{'state': 'public'})
     # Load zones
     shop = get_context().resource.parent
     zones = []
     handler = shop.get_resource('countries-zones').handler
     for record in handler.get_records():
         zones.append(handler.get_record_value(record, 'title'))
     # Create history
     cls.shipping_history_cls._make_resource(cls.shipping_history_cls,
                           folder, '%s/history' % name)
     # Import CSV with prices
     ShippingPrices._make_resource(ShippingPrices, folder,
                                   '%s/prices' % name)
     if getattr(cls, 'csv', None):
         table = ShippingPricesTable()
         csv = ro_database.get_handler(get_abspath(cls.csv), ShippingPricesCSV)
         for row in csv.get_rows():
             table.add_record(
               {'zone': str(zones.index(row.get_value('zone'))),
                'max-weight': row.get_value('max-weight'),
                'price': row.get_value('price')})
         folder.set_handler('%s/prices' % name, table)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)