def get_namespace(self, resource, context): prices = [] prices_resource = resource.get_resource('prices-range') get_record_value = prices_resource.handler.get_record_value for record in prices_resource.handler.get_records(): min_price = get_record_value(record, 'min') max_price = get_record_value(record, 'max') min_price_q = int(min_price * 100) if min_price else None max_price_q = int(max_price * 100) if max_price else None value = min_price_q, max_price_q min_price = format_price(min_price) if min_price else None max_price = format_price(max_price) if max_price else None checked = context.query.get('stored_price') == value prices.append({ 'value': IntegerRange.encode(value), 'checked': checked, 'css': 'selected' if checked else None, 'min': min_price, 'max': max_price }) no_range_price_checked = context.query.get('stored_price') == None namespace = { 'title': resource.get_title(), 'no_range_price_checked': no_range_price_checked, 'prices': prices } return namespace
def get_payment_way_description(self, context, total_amount): msg = MSG(u"Pay {percent}% of {original_amount} now ({amount})") percent = self.get_property('percent') if self.get_property('pay_tax'): total_amount = total_amount['with_tax'].split(' ')[0] total_amount = decimal(total_amount) else: total_amount = total_amount['without_tax'].split(' ')[0] total_amount = decimal(total_amount) amount = total_amount * (percent / decimal('100.0')) msg = msg.gettext(percent=percent, original_amount=format_price(total_amount), amount=format_price(amount)) return list(XMLParser(msg.encode('utf-8'))) + self.get_property('data')
def get_record_namespace(self, context, record): get_value = self.handler.get_record_value namespace = {'id': record.id, 'complete_id': '%s-%s' % (self.parent.name, record.id), 'payment_mode': self.parent.name} # Base namespace for key in self.handler.record_properties.keys(): namespace[key] = get_value(record, key) # Amount amount = get_value(record, 'amount') namespace['amount'] = format_price(amount) # User users = context.root.get_resource('users') username = get_value(record, 'user') or '0' user = users.get_resource(username) namespace['username'] = username namespace['user_title'] = user.get_title() namespace['user_email'] = user.get_property('email') # State namespace['advance_state'] = None # Timestamp accept = context.accept_language value = self.handler.get_record_value(record, 'ts') namespace['ts'] = format_datetime(value, accept) return namespace
def get_namespace(self, resource, context): get_record_value = self.payment_table.get_record_value amount = get_record_value(self.record, 'amount') return {'is_ok': get_record_value(self.record, 'state'), 'amount': format_price(amount), 'ref': get_record_value(self.record, 'ref'), 'address': self.payment_way.get_property('address')}
def get_item_value(self, resource, context, item, column): item_brain, item_resource = item if column == 'name': state = item_brain.workflow_state href = context.resource.get_pathto(item_resource) name = item_resource.get_reference() return XMLParser(numero_template % (states_color[state], href, name)) elif column == 'state': state = item_brain.workflow_state state_title = states[state].gettext().encode('utf-8') href = context.resource.get_pathto(item_resource) return XMLParser(numero_template % (states_color[state], href, state_title)) elif column == 'total_price': price = item_resource.get_property(column) return format_price(price) elif column == 'order_pdf': if item_resource.get_resource('order', soft=True) is None: return img = """ <a href="./%s/order/;download"> <img src="/ui/icons/16x16/select_none.png"/> </a> """ % item_brain.name return XMLParser(img) elif column == 'bill': if item_resource.get_resource('bill', soft=True) is None: return img = """ <a href="./%s/bill/;download"> <img src="/ui/icons/16x16/pdf.png"/> </a> """ % item_brain.name return XMLParser(img) proxy = super(OrdersView, self) return proxy.get_item_value(resource, context, item, column)
def get_namespace(self, resource, context): ref = context.query['ref'] if ref is None: return {'ref': MSG(u'-'), 'amount': None, 'top_view': None} # Get informations about payment payment_handler = resource.get_resource('payments').handler query = [ PhraseQuery('ref', ref), PhraseQuery('user', context.user.name) ] results = payment_handler.search(AndQuery(*query)) if not results: raise ValueError, u'Payment invalid' record = results[0] amount = payment_handler.get_record_value(record, 'amount') # Get top view resource_validator = payment_handler.get_record_value( record, 'resource_validator') resource_validator = context.root.get_resource(resource_validator) top_view = None if resource_validator.end_view_top: top_view = resource_validator.end_view_top.GET(resource, context) return { 'ref': context.query['ref'], 'amount': format_price(amount), 'top_view': top_view }
def get_payment_way_description(self, context, total_amount): total_amount = total_amount['with_tax'] if not type(total_amount) is decimal: # XXX We don't need currency total_amount = decimal(total_amount.split(' ')[0]) amount_available = self.get_credit_available_for_user(context.user.name) remaining_amount = amount_available - total_amount if remaining_amount < decimal('0'): remaining_amount = decimal('0') namespace = {'amount_available': format_price(amount_available), 'has_to_complete_payment': amount_available < total_amount, 'amount_to_pay': format_price(total_amount-amount_available), 'remaining_amount': format_price(remaining_amount), 'total_amount': format_price(total_amount)} description_template = self.get_resource( '/ui/backoffice/payments/credit/description.xml') return stl(description_template, namespace=namespace)
def get_price_with_tax(self, id_declination=None, with_reduction=True, pretty=False, prefix=None): price = self.get_price_without_tax(id_declination, with_reduction=with_reduction, prefix=prefix) price = price * self.get_tax_value(prefix=prefix) # Format price if pretty is True: return format_price(price) return price
def get_namespace(self, resource, context): namespace = {} get_record_value = self.payment_table.get_record_value for key in self.payment_table.record_properties: namespace[key] = get_record_value(self.record, key) namespace['amount'] = format_price(namespace['amount']) namespace['advance_state'] = PayboxStatus.get_value( namespace['advance_state']) return namespace
def get_javascript_namespace(self, declinations): # XXX # We have to Add price without tax (Before and after reduction) # XXX If handle_stock property is false manage_stock should be false manage_stock = self.get_stock_option() != 'accept' purchase_options_names = self.get_purchase_options_names() # Base product stock_quantity = self.get_property('stock-quantity') products = {} if len(declinations) == 0: products['base_product'] = { 'price_ht': format_price(self.get_price_without_tax()), 'price_ttc': format_price(self.get_price_with_tax()), 'weight': str(self.get_weight()), 'image': [], 'option': {}, 'is_default': True, 'stock': stock_quantity if manage_stock else None } # Other products (declinations) for declination in declinations: dynamic_schema = declination.get_dynamic_schema() stock_quantity = declination.get_quantity_in_stock() price_ht = self.get_price_without_tax( id_declination=declination.name) price_ttc = self.get_price_with_tax( id_declination=declination.name) image = None #declination.get_property('associated-image') products[declination.name] = { 'price_ht': format_price(price_ht), 'price_ttc': format_price(price_ttc), 'weight': str(declination.get_weight()), 'image': get_uri_name(image) if image else None, 'is_default': declination.get_property('is_default'), 'option': {}, 'stock': stock_quantity if manage_stock else None } for name in purchase_options_names: value = declination.get_dynamic_property(name, dynamic_schema) if value: products[declination.name]['option'][name] = value return dumps(products)
def get_credit_namespace_available_for_user(self, user_name): ns = [] users_credit = self.get_resource('users-credit').handler results = users_credit.search(user=user_name) if len(results) == 0: return ns get_value = users_credit.get_record_value for record in results: amount = get_value(record, 'amount') ns.append({'user': get_value(record, 'user'), 'description': get_value(record, 'description'), 'amount': format_price(amount)}) return ns
def get_javascript_namespace(self, declinations): # XXX # We have to Add price without tax (Before and after reduction) # XXX If handle_stock property is false manage_stock should be false manage_stock = self.get_stock_option() != 'accept' purchase_options_names = self.get_purchase_options_names() # Base product stock_quantity = self.get_property('stock-quantity') products = {} if len(declinations)==0: products['base_product'] = { 'price_ht': format_price(self.get_price_without_tax()), 'price_ttc': format_price(self.get_price_with_tax()), 'weight': str(self.get_weight()), 'image': [], 'option': {}, 'is_default': True, 'stock': stock_quantity if manage_stock else None} # Other products (declinations) for declination in declinations: dynamic_schema = declination.get_dynamic_schema() stock_quantity = declination.get_quantity_in_stock() price_ht = self.get_price_without_tax(id_declination=declination.name) price_ttc = self.get_price_with_tax(id_declination=declination.name) image = None#declination.get_property('associated-image') products[declination.name] = { 'price_ht': format_price(price_ht), 'price_ttc': format_price(price_ttc), 'weight': str(declination.get_weight()), 'image': get_uri_name(image) if image else None, 'is_default': declination.get_property('is_default'), 'option': {}, 'stock': stock_quantity if manage_stock else None} for name in purchase_options_names: value = declination.get_dynamic_property(name, dynamic_schema) if value: products[declination.name]['option'][name] = value return dumps(products)
def get_namespace(self, resource, context): prices = [] prices_resource = resource.get_resource('prices-range') get_record_value = prices_resource.handler.get_record_value for record in prices_resource.handler.get_records(): min_price = get_record_value(record, 'min') max_price = get_record_value(record, 'max') min_price_q = int(min_price * 100) if min_price else None max_price_q = int(max_price * 100) if max_price else None value = min_price_q, max_price_q min_price = format_price(min_price) if min_price else None max_price = format_price(max_price) if max_price else None checked = context.query.get('stored_price') == value prices.append({'value': IntegerRange.encode(value), 'checked': checked, 'css': 'selected' if checked else None, 'min': min_price, 'max': max_price}) no_range_price_checked = context.query.get('stored_price') == None namespace = {'title': resource.get_title(), 'no_range_price_checked': no_range_price_checked, 'prices': prices} return namespace
def send_confirmation_mail(self, payment_way, id_record, context): root = context.root payments_table = payment_way.get_resource('payments').handler record = payments_table.get_record(id_record) user = payments_table.get_record_value(record, 'user') user = root.get_resource('users/%s' % user) recipient = user.get_property('email') subject = self.mail_subject_template.gettext() amount = payments_table.get_record_value(record, 'amount') text = self.mail_body_template.gettext(id=id_record, payment_way=payment_way.name, ref=payments_table.get_record_value(record, 'ref'), amount=format_price(amount), subject_with_host=False) root.send_email(recipient, subject, text=text)
def send_confirmation_mail(self, payment_way, id_record, context): root = context.root payments_table = payment_way.get_resource('payments').handler record = payments_table.get_record(id_record) user = payments_table.get_record_value(record, 'user') user = root.get_resource('users/%s' % user) recipient = user.get_property('email') subject = self.mail_subject_template.gettext() amount = payments_table.get_record_value(record, 'amount') text = self.mail_body_template.gettext( id=id_record, payment_way=payment_way.name, ref=payments_table.get_record_value(record, 'ref'), amount=format_price(amount), subject_with_host=False) root.send_email(recipient, subject, text=text)
def get_price_without_tax(self, id_declination=None, with_reduction=True, pretty=False, prefix=None): if prefix is None: prefix = self.get_price_prefix() # Base price if with_reduction is True and self.get_property('%shas_reduction' % prefix): price = self.get_property('%sreduce-pre-tax-price' % prefix) else: price = self.get_property('%spre-tax-price' % prefix) # Declination if id_declination: declination = self.get_resource(id_declination) price = price + declination.get_price_impact(prefix) # Format price if pretty is True: return format_price(price) return price
def get_default_shipping_way(self, context, widgets): if len(widgets) == 1: return widgets[0] price = decimal('0') for widget in widgets: price += widget['price'] logo_uri = self.get_property('default_shipping_way_logo') if logo_uri is not None: logo = self.get_resource(logo_uri, soft=True) img = context.resource.get_pathto(logo) else: img = None return { 'title': self.get_property('default_shipping_way_title'), 'description': self.get_property('default_shipping_way_description'), 'enabled': True, 'img': img, 'name': 'default', 'pretty_price': format_price(price), 'price': price}
def get_price_without_tax(self, id_declination=None, with_reduction=True, pretty=False, prefix=None): if prefix is None: prefix = self.get_price_prefix() # Base price if with_reduction is True and self.get_property( '%shas_reduction' % prefix): price = self.get_property('%sreduce-pre-tax-price' % prefix) else: price = self.get_property('%spre-tax-price' % prefix) # Declination if id_declination: declination = self.get_resource(id_declination) price = price + declination.get_price_impact(prefix) # Format price if pretty is True: return format_price(price) return price
def get_default_shipping_way(self, context, widgets): if len(widgets) == 1: return widgets[0] price = decimal('0') for widget in widgets: price += widget['price'] logo_uri = self.get_property('default_shipping_way_logo') if logo_uri is not None: logo = self.get_resource(logo_uri, soft=True) img = context.resource.get_pathto(logo) else: img = None return { 'title': self.get_property('default_shipping_way_title'), 'description': self.get_property('default_shipping_way_description'), 'enabled': True, 'img': img, 'name': 'default', 'pretty_price': format_price(price), 'price': price }
def get_widget_namespace(self, context, country, list_weight): # Is enabled ? if not self.get_property('enabled'): return None # For good group ? shipping_groups = self.get_property('only_this_groups') if (shipping_groups and context.user.get_property('user_group') not in shipping_groups): return None # Get price of shipping price = self.get_price(country, list_weight) if price is None: return None language = self.get_content_language(context) ns = {'name': self.name, 'img': self.get_logo(context), 'title': self.get_title(language), 'pretty_price': format_price(price), 'price': price} for key in ['description', 'enabled']: ns[key] = self.get_property(key, language) return ns
def get_namespace(self, resource, context): ref = context.query['ref'] if ref is None: return {'ref': MSG(u'-'), 'amount': None, 'top_view': None} # Get informations about payment payment_handler = resource.get_resource('payments').handler query = [PhraseQuery('ref', ref), PhraseQuery('user', context.user.name)] results = payment_handler.search(AndQuery(*query)) if not results: raise ValueError, u'Payment invalid' record = results[0] amount = payment_handler.get_record_value(record, 'amount') # Get top view resource_validator = payment_handler.get_record_value(record, 'resource_validator') resource_validator = context.root.get_resource(resource_validator) top_view = None if resource_validator.end_view_top: top_view = resource_validator.end_view_top.GET(resource, context) return {'ref': context.query['ref'], 'amount': format_price(amount), 'top_view': top_view}
def get_namespace(self, resource, context): # Get some resources shop = get_shop(resource) addresses = shop.get_resource('addresses').handler # Build namespace namespace = resource.get_namespace(context) for key in ['is_payed', 'is_sent']: namespace[key] = resource.get_property(key) # States namespace['is_canceled'] = resource.get_statename() == 'cancel' namespace['state'] = {'title': states[resource.workflow_state], 'color': states_color[resource.workflow_state]} namespace['transitions'] = SelectWidget('transition').to_html(Order_Transitions, None) # Bill has_bill = resource.get_resource('bill', soft=True) is not None namespace['has_bill'] = has_bill has_order = resource.get_resource('order', soft=True) is not None namespace['has_order'] = has_order # Order creation_datetime = resource.get_property('creation_datetime') namespace['order'] = { 'id': resource.name, 'date': format_datetime(creation_datetime, context.accept_language)} for key in ['shipping_price', 'total_price', 'total_weight']: namespace['order'][key] =resource.get_property(key) namespace['order']['shipping_way'] = ShippingWaysEnumerate.get_value( resource.get_property('shipping')) namespace['order']['payment_way'] = PaymentWaysEnumerate.get_value( resource.get_property('payment_mode')) # Delivery and shipping addresses get_address = addresses.get_record_namespace delivery_address = resource.get_property('delivery_address') bill_address = resource.get_property('bill_address') namespace['delivery_address'] = get_address(delivery_address) namespace['bill_address'] = get_address(bill_address) # Price for key in ['shipping_price', 'total_price']: price = resource.get_property(key) namespace[key] = format_price(price) # Messages messages = resource.get_resource('messages') namespace['messages'] = messages.get_namespace_messages(context) # Payments (We show last payment) namespace['payments'] = [] payments = shop.get_resource('payments') for payment_way, payment_record in payments.get_payments_records(context, resource.name): payment_table = payment_way.get_resource('payments').handler # Get specific view (useless now ?) view = payment_way.order_edit_view view = view( payment_way=payment_way, payment_table=payment_table, record=payment_record, id_payment=payment_record.id) view = view.GET(resource, context) # Details details = [] for name, datatype in payment_table.record_properties.items(): if name in ('resource_validator', 'state', 'ref', 'user'): continue value = payment_table.get_record_value(payment_record, name) if issubclass(datatype, Enumerate): value = datatype.get_value(value) details.append({'title': getattr(datatype, 'title', name), 'value': value}) # Is payed ? is_payed = payment_table.get_record_value(payment_record, 'state') # BUild namespace namespace['payments'].append({'is_payed': is_payed, 'title': payment_way.get_title(), 'details': details, 'state': payment_table.get_record_value(payment_record, 'state'), 'view': view}) namespace['last_payment'] = namespace['payments'][0] namespace['payment_ways'] = SelectWidget('payment_way', has_empty_option=False).to_html(PaymentWaysEnumerate, resource.get_property('payment_way')) # Shippings is_sent = resource.get_property('is_sent') shippings = shop.get_resource('shippings') shipping_way = resource.get_property('shipping') if shipping_way == 'default': shippings_records = None else: shipping_way_resource = shop.get_resource('shippings/%s/' % shipping_way) shippings_records = shippings.get_shippings_records(context, resource.name) if is_sent: view = None if shippings_records: # We show last delivery last_delivery = shippings_records[0] edit_record_view = shipping_way_resource.order_edit_view view = edit_record_view.GET(resource, shipping_way_resource, last_delivery, context) elif shippings_records is None and shipping_way == 'default': view = None else: # We have to add delivery add_record_view = shipping_way_resource.order_add_view if add_record_view: view = add_record_view.GET(shipping_way_resource, context) else: view = None namespace['shipping_ways'] = SelectWidget('shipping_way', has_empty_option=False).to_html(ShippingWaysEnumerate, shipping_way) namespace['shipping'] = {'is_sent': is_sent, 'view': view} return namespace
def get_namespace(self, context): # Get some resources shop = get_shop(self) order_products = self.get_resource('products') # Get creation date accept = context.accept_language creation_date = self.get_property('creation_datetime') creation_date = format_date(creation_date, accept=accept) # Build namespace namespace = {'products': [], 'reference': self.get_reference(), 'creation_date': creation_date, 'price': {'shippings': {'with_tax': decimal(0), 'without_tax': decimal(0)}, 'products': {'with_tax': decimal(0), 'without_tax': decimal(0)}, 'total': {'with_tax': decimal(0), 'without_tax': decimal(0)}}} # Build order products namespace get_value = order_products.handler.get_record_value for record in order_products.handler.get_records(): kw = {'id': record.id, 'href': None, 'category': None} for key in BaseOrdersProducts.record_properties.keys(): kw[key] = get_value(record, key) name = get_value(record, 'name') product_resource = context.root.get_resource(name, soft=True) if product_resource: kw['href'] = context.get_link(product_resource) kw['key'] = product_resource.handler.key kw['cover'] = product_resource.get_cover_namespace(context) kw['category'] = product_resource.parent.get_title() # Declination if kw['declination']: declination = product_resource.get_resource( str(kw['declination']), soft=True) if declination: kw['declination'] = declination.get_declination_title() else: kw['cover'] = None # Get product prices unit_price_with_tax = kw['pre-tax-price'] * ((kw['tax']/100)+1) unit_price_without_tax = kw['pre-tax-price'] total_price_with_tax = unit_price_with_tax * kw['quantity'] total_price_without_tax = unit_price_without_tax * kw['quantity'] kw['price'] = { 'unit': {'with_tax': format_price(unit_price_with_tax), 'without_tax': format_price(unit_price_without_tax)}, 'total': {'with_tax': format_price(total_price_with_tax), 'without_tax': format_price(total_price_without_tax)}} namespace['products'].append(kw) # Calcul order price namespace['price']['products']['with_tax'] += total_price_with_tax namespace['price']['products']['without_tax'] += total_price_without_tax # Format price shipping_price = self.get_property('shipping_price') namespace['price']['total']['with_tax'] = format_price( namespace['price']['products']['with_tax'] + shipping_price) namespace['price']['products']['with_tax'] = format_price( namespace['price']['products']['with_tax']) namespace['price']['products']['without_tax'] = format_price( namespace['price']['products']['without_tax']) namespace['price']['shippings']['with_tax'] = format_price( shipping_price) # Customer customer_id = self.get_property('customer_id') user = context.root.get_user(customer_id) namespace['customer'] = {'id': customer_id, 'title': user.get_title(), 'email': user.get_property('email'), 'phone1': user.get_property('phone1'), 'phone2': user.get_property('phone2')} # Addresses addresses = shop.get_resource('addresses').handler get_address = addresses.get_record_namespace bill_address = self.get_property('bill_address') delivery_address = self.get_property('delivery_address') namespace['delivery_address'] = get_address(delivery_address) namespace['bill_address'] = get_address(bill_address) # Carrier namespace['carrier'] = u'xxx' namespace['payment_way'] = u'xxx' return namespace
def get_namespace(self, resource, context): # Get some resources shop = get_shop(resource) addresses = shop.get_resource('addresses').handler # Build namespace namespace = resource.get_namespace(context) for key in ['is_payed', 'is_sent']: namespace[key] = resource.get_property(key) # States namespace['is_canceled'] = resource.get_statename() == 'cancel' namespace['state'] = { 'title': states[resource.workflow_state], 'color': states_color[resource.workflow_state] } namespace['transitions'] = SelectWidget('transition').to_html( Order_Transitions, None) # Bill has_bill = resource.get_resource('bill', soft=True) is not None namespace['has_bill'] = has_bill has_order = resource.get_resource('order', soft=True) is not None namespace['has_order'] = has_order # Order creation_datetime = resource.get_property('creation_datetime') namespace['order'] = { 'id': resource.name, 'date': format_datetime(creation_datetime, context.accept_language) } for key in ['shipping_price', 'total_price', 'total_weight']: namespace['order'][key] = resource.get_property(key) namespace['order']['shipping_way'] = ShippingWaysEnumerate.get_value( resource.get_property('shipping')) namespace['order']['payment_way'] = PaymentWaysEnumerate.get_value( resource.get_property('payment_mode')) # Delivery and shipping addresses get_address = addresses.get_record_namespace delivery_address = resource.get_property('delivery_address') bill_address = resource.get_property('bill_address') namespace['delivery_address'] = get_address(delivery_address) namespace['bill_address'] = get_address(bill_address) # Price for key in ['shipping_price', 'total_price']: price = resource.get_property(key) namespace[key] = format_price(price) # Messages messages = resource.get_resource('messages') namespace['messages'] = messages.get_namespace_messages(context) # Payments (We show last payment) namespace['payments'] = [] payments = shop.get_resource('payments') for payment_way, payment_record in payments.get_payments_records( context, resource.name): payment_table = payment_way.get_resource('payments').handler # Get specific view (useless now ?) view = payment_way.order_edit_view view = view(payment_way=payment_way, payment_table=payment_table, record=payment_record, id_payment=payment_record.id) view = view.GET(resource, context) # Details details = [] for name, datatype in payment_table.record_properties.items(): if name in ('resource_validator', 'state', 'ref', 'user'): continue value = payment_table.get_record_value(payment_record, name) if issubclass(datatype, Enumerate): value = datatype.get_value(value) details.append({ 'title': getattr(datatype, 'title', name), 'value': value }) # Is payed ? is_payed = payment_table.get_record_value(payment_record, 'state') # BUild namespace namespace['payments'].append({ 'is_payed': is_payed, 'title': payment_way.get_title(), 'details': details, 'state': payment_table.get_record_value(payment_record, 'state'), 'view': view }) namespace['last_payment'] = namespace['payments'][0] namespace['payment_ways'] = SelectWidget( 'payment_way', has_empty_option=False).to_html( PaymentWaysEnumerate, resource.get_property('payment_way')) # Shippings is_sent = resource.get_property('is_sent') shippings = shop.get_resource('shippings') shipping_way = resource.get_property('shipping') if shipping_way == 'default': shippings_records = None else: shipping_way_resource = shop.get_resource('shippings/%s/' % shipping_way) shippings_records = shippings.get_shippings_records( context, resource.name) if is_sent: view = None if shippings_records: # We show last delivery last_delivery = shippings_records[0] edit_record_view = shipping_way_resource.order_edit_view view = edit_record_view.GET(resource, shipping_way_resource, last_delivery, context) elif shippings_records is None and shipping_way == 'default': view = None else: # We have to add delivery add_record_view = shipping_way_resource.order_add_view if add_record_view: view = add_record_view.GET(shipping_way_resource, context) else: view = None namespace['shipping_ways'] = SelectWidget( 'shipping_way', has_empty_option=False).to_html(ShippingWaysEnumerate, shipping_way) namespace['shipping'] = {'is_sent': is_sent, 'view': view} return namespace
def get_namespace(self, context): # Get some resources shop = get_shop(self) order_products = self.get_resource('products') # Get creation date accept = context.accept_language creation_date = self.get_property('creation_datetime') creation_date = format_date(creation_date, accept=accept) # Build namespace namespace = { 'products': [], 'reference': self.get_reference(), 'creation_date': creation_date, 'price': { 'shippings': { 'with_tax': decimal(0), 'without_tax': decimal(0) }, 'products': { 'with_tax': decimal(0), 'without_tax': decimal(0) }, 'total': { 'with_tax': decimal(0), 'without_tax': decimal(0) } } } # Build order products namespace get_value = order_products.handler.get_record_value for record in order_products.handler.get_records(): kw = {'id': record.id, 'href': None, 'category': None} for key in BaseOrdersProducts.record_properties.keys(): kw[key] = get_value(record, key) name = get_value(record, 'name') product_resource = context.root.get_resource(name, soft=True) if product_resource: kw['href'] = context.get_link(product_resource) kw['key'] = product_resource.handler.key kw['cover'] = product_resource.get_cover_namespace(context) kw['category'] = product_resource.parent.get_title() # Declination if kw['declination']: declination = product_resource.get_resource(str( kw['declination']), soft=True) if declination: kw['declination'] = declination.get_declination_title() else: kw['cover'] = None # Get product prices unit_price_with_tax = kw['pre-tax-price'] * ((kw['tax'] / 100) + 1) unit_price_without_tax = kw['pre-tax-price'] total_price_with_tax = unit_price_with_tax * kw['quantity'] total_price_without_tax = unit_price_without_tax * kw['quantity'] kw['price'] = { 'unit': { 'with_tax': format_price(unit_price_with_tax), 'without_tax': format_price(unit_price_without_tax) }, 'total': { 'with_tax': format_price(total_price_with_tax), 'without_tax': format_price(total_price_without_tax) } } namespace['products'].append(kw) # Calcul order price namespace['price']['products']['with_tax'] += total_price_with_tax namespace['price']['products'][ 'without_tax'] += total_price_without_tax # Format price shipping_price = self.get_property('shipping_price') namespace['price']['total']['with_tax'] = format_price( namespace['price']['products']['with_tax'] + shipping_price) namespace['price']['products']['with_tax'] = format_price( namespace['price']['products']['with_tax']) namespace['price']['products']['without_tax'] = format_price( namespace['price']['products']['without_tax']) namespace['price']['shippings']['with_tax'] = format_price( shipping_price) # Customer customer_id = self.get_property('customer_id') user = context.root.get_user(customer_id) namespace['customer'] = { 'id': customer_id, 'title': user.get_title(), 'email': user.get_property('email'), 'phone1': user.get_property('phone1'), 'phone2': user.get_property('phone2') } # Addresses addresses = shop.get_resource('addresses').handler get_address = addresses.get_record_namespace bill_address = self.get_property('bill_address') delivery_address = self.get_property('delivery_address') namespace['delivery_address'] = get_address(delivery_address) namespace['bill_address'] = get_address(bill_address) # Carrier namespace['carrier'] = u'xxx' namespace['payment_way'] = u'xxx' return namespace