Esempio n. 1
0
 def get_metadata_schema(cls):
     return merge_dicts(ShopFolder.get_metadata_schema(),
                        data=XHTMLBody(multilingual=True),
                        title=Unicode(multilingual=True),
                        enabled=Boolean(default=True),
                        only_this_groups=UserGroup_Enumerate(multiple=True),
                        logo=ImagePathDataType(multilingual=True))
Esempio n. 2
0
class PaymentWay_Configure(DBResource_Edit):

    access = 'is_admin'

    schema = {
        'title': Unicode(mandatory=True, multilingual=True),
        'logo': ImagePathDataType(mandatory=True, multilingual=True),
        'data': XHTMLBody(mandatory=True, multilingual=True),
        'only_this_groups': UserGroup_Enumerate(multiple=True),
        'enabled': Boolean(mandatory=True)
    }

    widgets = [
        TextWidget('title', title=MSG(u'Title')),
        ImageSelectorWidget('logo', title=MSG(u'Logo')),
        BooleanRadio('enabled', title=MSG(u'Enabled ?')),
        RTEWidget('data', title=MSG(u"Description")),
        SelectWidget('only_this_groups', title=MSG(u"Only for this groups"))
    ]

    submit_value = MSG(u'Edit configuration')

    def get_value(self, resource, context, name, datatype):
        language = resource.get_content_language(context)
        return resource.get_property(name, language=language)

    def action(self, resource, context, form):
        language = resource.get_content_language(context)
        for key, datatype in self.schema.items():
            if getattr(datatype, 'multilingual', False):
                resource.set_property(key, form[key], language=language)
            else:
                resource.set_property(key, form[key])
        return context.come_back(messages.MSG_CHANGES_SAVED, goto='./')
Esempio n. 3
0
 def action_export_as_ods(self, resource, context, form):
     if lpod_is_install is False:
         msg = ERROR(u'Please install LPOD')
         return context.come_back(msg)
     # XXX Create a new process and send ODS file by mail for performances ?
     # XXX We do not export product without declination
     # XXX We do not export product without product model
     # Get list of groups
     groups = []
     for option in UserGroup_Enumerate.get_options():
         group = context.root.get_resource(option['name'])
         if group.get_property('use_default_price') is True:
             continue
         groups.append(group)
     # DB
     root = context.root
     shop = get_shop(resource)
     document = odf_new_document_from_type('spreadsheet')
     body = document.get_body()
     models = shop.get_resource('products-models').get_resources()
     for product_model in models:
         lines = []
         # We create one TAB by product model
         table = odf_create_table(product_model.get_title())
         search = root.search(product_model=str(product_model.get_abspath()))
         for brain in search.get_documents():
               product = root.get_resource(brain.abspath)
               for d in product.search_resources(cls=Declination):
                   # Ref - Declination name - Declination title
                   line = [product.get_property('reference'),
                           d.name,
                           d.get_declination_title().encode('utf-8')]
                   # Stock
                   line.append(str(d.get_quantity_in_stock()))
                   # Price by group (HT or TTC)
                   for group in groups:
                       k_price = {'id_declination': d.name,
                                  'prefix': group.get_prefix(),
                                  'pretty': True}
                       if group.get_property('show_ht_price'):
                           price = product.get_price_without_tax(**k_price)
                       else:
                           price = product.get_price_with_tax(**k_price)
                       line.append(str(price))
                   # Add row
                   lines.append(','.join(line))
         data = '\n'.join(lines)
         table = import_from_csv(StringIO(data), product_model.name)
         body.append(table)
     # Extport as ODS
     f = StringIO()
     document.save(f)
     content = f.getvalue()
     f.close()
     # Return ODS
     context.set_content_type('application/vnd.oasis.opendocument.spreadsheet')
     context.set_content_disposition('attachment', 'export.ods')
     return content
Esempio n. 4
0
 def get_schema(self, resource, context):
     product_model = resource.get_product_model()
     site_root = resource.get_site_root()
     shop = get_shop(site_root)
     # Cover is mandatory
     mandatory = shop.get_property('product_cover_is_mandatory')
     product_schema['cover'].mandatory = mandatory
     # Return schema
     return merge_dicts(
               product_schema,
               (product_model.get_model_schema() if product_model else {}),
               data=XHTMLBody(multilingual=True),
               category=CategoriesEnumerate,
               not_buyable_by_groups=UserGroup_Enumerate(multiple=True),
               tags=TagsList(site_root=site_root, multiple=True))
Esempio n. 5
0
 def get_table_columns(self, resource, context):
     columns = []
     shop = get_shop(resource)
     enumerates_folder = shop.get_resource('enumerates')
     # Purchase options columns
     for name in resource.get_purchase_options_names():
         title = enumerates_folder.get_resource(name).get_title()
         columns.append((name, title))
     # Groups price
     for group in UserGroup_Enumerate.get_options():
         group = context.root.get_resource(group['name'])
         if group.get_property('use_default_price') is True:
             continue
         if group.get_property('show_ht_price'):
             tax = 'HT'
         else:
             tax = 'TTC'
         title = MSG(u'Price {g} {t}').gettext(g=group.get_title(), t=tax)
         columns.append(('price-%s' % group.name, title))
     return self.base_columns + columns
Esempio n. 6
0
 def get_namespace(self, datatype, value):
     context = get_context()
     namespace = {'groups': []}
     for group in UserGroup_Enumerate.get_options():
         prefix = ''
         abspath = group['name']
         resource_group = context.root.get_resource(abspath)
         if resource_group.get_property('use_default_price'):
             continue
         group['id'] = resource_group.name
         if group['id'] != 'default':
             prefix = '%s-' % group['id']
         widget_name = '%simpact_on_price' % prefix
         try:
             value = context.resource.get_property(widget_name)
         except:
             # XXX Fix a bug
             value = None
         group['widget'] = DeclinationPriceWidget(widget_name,
                             prefix=prefix).to_html(None, value)
         namespace['groups'].append(group)
     return namespace
Esempio n. 7
0
 def get_namespace(self, datatype, value):
     context = get_context()
     namespace = {'groups': []}
     for group in UserGroup_Enumerate.get_options():
         prefix = ''
         abspath = group['name']
         resource_group = context.root.get_resource(abspath)
         if resource_group.get_property('use_default_price'):
             continue
         group['id'] = resource_group.name
         if group['id'] != 'default':
             prefix = '%s-' % group['id']
         widget_name = '%simpact_on_price' % prefix
         try:
             value = context.resource.get_property(widget_name)
         except:
             # XXX Fix a bug
             value = None
         group['widget'] = DeclinationPriceWidget(widget_name,
                                                  prefix=prefix).to_html(
                                                      None, value)
         namespace['groups'].append(group)
     return namespace
Esempio n. 8
0
File: taxes.py Progetto: hforge/shop
 def get_namespace(self, datatype, value):
     context = get_context()
     namespace = {'groups': []}
     is_product = context.resource.class_id == 'product'
     if is_product:
         not_buyable_by_groups = context.resource.get_property('not_buyable_by_groups')
     else:
         not_buyable_by_groups = []
     for group in UserGroup_Enumerate.get_options():
         prefix = ''
         group['id'] = get_uri_name(group['name'])
         if group['id'] != 'default':
             prefix = '%s-' % group['id']
         group['not_buyable'] = group['name'] in not_buyable_by_groups
         widget_name = '%spre-tax-price' % prefix
         if is_product:
             value = context.resource.get_property(widget_name)
         else:
             value = None
         group['widget'] = PriceWidget(widget_name,
                             prefix=prefix).to_html(None, value)
         namespace['groups'].append(group)
     return namespace
Esempio n. 9
0
 def get_namespace(self, datatype, value):
     context = get_context()
     namespace = {'groups': []}
     is_product = context.resource.class_id == 'product'
     if is_product:
         not_buyable_by_groups = context.resource.get_property(
             'not_buyable_by_groups')
     else:
         not_buyable_by_groups = []
     for group in UserGroup_Enumerate.get_options():
         prefix = ''
         group['id'] = get_uri_name(group['name'])
         if group['id'] != 'default':
             prefix = '%s-' % group['id']
         group['not_buyable'] = group['name'] in not_buyable_by_groups
         widget_name = '%spre-tax-price' % prefix
         if is_product:
             value = context.resource.get_property(widget_name)
         else:
             value = None
         group['widget'] = PriceWidget(widget_name,
                                       prefix=prefix).to_html(None, value)
         namespace['groups'].append(group)
     return namespace
Esempio n. 10
0
 def get_items(self, resource, context):
     shop = get_shop(resource)
     items = []
     groups = []
     # Get list of groups
     for option in UserGroup_Enumerate.get_options():
         group = context.root.get_resource(option['name'])
         groups.append(group)
     # Get all declinations
     for declination in resource.search_resources(cls=Declination):
         name = declination.name
         title = declination.get_property('title')
         if not title:
             title = declination.get_declination_title()
         kw = {'checkbox': (name, True),
               'title': (title, name)}
         for key in ['reference', 'stock-quantity']:
             kw[key] = declination.get_property(key)
         declination_dynamic_schema = declination.get_dynamic_schema()
         for name, datatype in declination_dynamic_schema.items():
             value = declination.get_dynamic_property(name, declination_dynamic_schema)
             if value:
                 kw[name] = datatype.get_value(value)
             else:
                 kw[name] = None
         # Img
         img = None#declination.get_property('associated-image')
         if img:
             img = context.get_link(context.root.get_resource(img))
             kw['img'] = XMLParser('<img src="%s/;thumb?width=150&amp;height=150"/>' % img)
         else:
             kw['img'] = None
         # Barcode
         shop_uri = context.resource.get_pathto(shop)
         reference = declination.get_property('reference')
         kw['barcode'] = XMLParser('<img src="%s/;barcode?reference=%s"/>' %
                                   (shop_uri, reference))
         # Weight
         base_weight = resource.get_property('weight')
         weight_impact = declination.get_property('impact-on-weight')
         weight_value = declination.get_property('weight-impact-value')
         if weight_impact == 'none':
             kw['weight'] = u'%s ' % base_weight
         elif weight_impact == 'increase':
             kw['weight'] = u'%s kg' % (base_weight + weight_value)
             kw['weight'] += u' (+ %s kg)' % (base_weight + weight_value)
         elif weight_impact == 'decrease':
             kw['weight'] = u'%s kg' % (base_weight - weight_value)
             kw['weight'] += u' (- %s kg)' % (base_weight - weight_value)
         # Price
         for group in groups:
             if group.get_property('use_default_price') is True:
                 continue
             k_price = {'id_declination': declination.name,
                        'prefix': group.get_prefix(),
                        'pretty': True}
             if group.get_property('show_ht_price'):
                 price = resource.get_price_without_tax(**k_price)
             else:
                 price = resource.get_price_with_tax(**k_price)
             kw['price-%s' % group.name] = price
         # Default ?
         is_default = declination.get_property('is_default')
         kw['is_default'] = bool_to_img(is_default)
         items.append(kw)
     return items
Esempio n. 11
0
from itools.datatypes import Decimal
from itools.gettext import MSG

# Import from products
from shop.products.enumerate import ProductModelsEnumerate
from shop.datatypes import UserGroup_Enumerate


class DeliveryModes(Enumerate):

    options = [{
        'name': 'weight',
        'value': MSG(u'Depends of weight')
    }, {
        'name': 'quantity',
        'value': MSG(u'Depends of quantity')
    }]


delivery_schema = {
    'title': Unicode,
    'logo': PathDataType,
    'description': Unicode,
    'enabled': Boolean(default=True),
    'mode': DeliveryModes(default='weight'),
    'only_this_models': ProductModelsEnumerate(multiple=True),
    'only_this_groups': UserGroup_Enumerate(multiple=True),
    'insurance': Decimal(default=decimal(0)),
    'is_free': Boolean
}
Esempio n. 12
0
 def action_export_as_ods(self, resource, context, form):
     if lpod_is_install is False:
         msg = ERROR(u'Please install LPOD')
         return context.come_back(msg)
     # XXX Create a new process and send ODS file by mail for performances ?
     # XXX We do not export product without declination
     # XXX We do not export product without product model
     # Get list of groups
     groups = []
     for option in UserGroup_Enumerate.get_options():
         group = context.root.get_resource(option['name'])
         if group.get_property('use_default_price') is True:
             continue
         groups.append(group)
     # DB
     root = context.root
     shop = get_shop(resource)
     document = odf_new_document_from_type('spreadsheet')
     body = document.get_body()
     models = shop.get_resource('products-models').get_resources()
     for product_model in models:
         lines = []
         # We create one TAB by product model
         table = odf_create_table(product_model.get_title())
         search = root.search(
             product_model=str(product_model.get_abspath()))
         for brain in search.get_documents():
             product = root.get_resource(brain.abspath)
             for d in product.search_resources(cls=Declination):
                 # Ref - Declination name - Declination title
                 line = [
                     product.get_property('reference'), d.name,
                     d.get_declination_title().encode('utf-8')
                 ]
                 # Stock
                 line.append(str(d.get_quantity_in_stock()))
                 # Price by group (HT or TTC)
                 for group in groups:
                     k_price = {
                         'id_declination': d.name,
                         'prefix': group.get_prefix(),
                         'pretty': True
                     }
                     if group.get_property('show_ht_price'):
                         price = product.get_price_without_tax(**k_price)
                     else:
                         price = product.get_price_with_tax(**k_price)
                     line.append(str(price))
                 # Add row
                 lines.append(','.join(line))
         data = '\n'.join(lines)
         table = import_from_csv(StringIO(data), product_model.name)
         body.append(table)
     # Extport as ODS
     f = StringIO()
     document.save(f)
     content = f.getvalue()
     f.close()
     # Return ODS
     context.set_content_type(
         'application/vnd.oasis.opendocument.spreadsheet')
     context.set_content_disposition('attachment', 'export.ods')
     return content