def _price_abonement(self, card_type, steps): """ This method calculate the abonement price. See logic_clientcard.xml. """ prices = dictlist_keyval(card_type['price_categories'], 'id', steps['price_category'])[0] count = int(steps['count_sold']) if count == 1: price = float(prices['once_price']) elif count == 4: price = float(prices['half_price']) elif count == 8: price = float(prices['full_price']) elif count > 8 and count % 8 == 0: price = float(prices['full_price']) * (count / 8) else: print _('Invalid usage. Why do you use count=%i' % count) price = float(0.0) steps['price'] = price return price
def coaches_callback(coach_id_list): from library import dictlist_keyval # get the coach descriptions' list using its id list coaches_dictlist = dictlist_keyval(self.parent.static['coaches'], 'id', coach_id_list) self.schedule_object.set_coaches(coaches_dictlist)
def assign_card(self): slug = self.wizard_dialog('list', _('Choose the card\'s type'), self.generate_card_list()) if not slug: # user has pressed 'Escape' or closes the dialog return file_name = '../uis/logic_clientcard.xml' xquery = "doc('%s')/logic/rule[@name='%s']/sequence" results = self.xml_query(file_name, xquery, slug) if results: sequence = QDomDocument() if not sequence.setContent(results): raise ValueError('could not parse XML:', results) card_type = dictlist_keyval(self.static['card_ordinary'], 'slug', slug)[0] steps = {'slug': str(slug)} root = sequence.documentElement() node = root.firstChild() while not node.isNull(): element = node.toElement() if 'dialog' == element.tagName(): if node.hasAttributes(): # get dialog's attributes dlg_type = element.attribute('type') dlg_title = element.attribute('title') dlg_name = element.attribute('name') static_key = element.hasAttribute('static') and str(element.attribute('static')) or None default = element.hasAttribute('default') and element.attribute('default') or 0 # get the result type info result_as = str(element.attribute('result_as')) result_types = {'integer': int, 'float': float} conv = result_types[result_as] # if there are child nodes, so if node.hasChildNodes(): child = node.firstChild() element = child.toElement() if 'calculate' == element.tagName(): # it needs to calculate the value using this class method if element.hasAttribute('function'): method_name = element.attribute('function') if hasattr(self, str(method_name)): function = eval('self.%s' % method_name) if callable(function): default = function(card_type, steps) else: print 'This is not a callable.' else: print 'This method is not defined in the class.' # show dialog and get a data from user result = None result = self.show_ui_dialog(dlg_type, dlg_title, default, static_key) if not result: # user has pressed 'Escape' or closes the dialog return # save user date with needed type steps[str(dlg_name)] = conv(result) # skip the following dialog if it needs # ToDo: skip all dialogs until the one if self.need_skip_next_dlg(node, conv, result): node = node.nextSibling() node = node.nextSibling() # end while #print card_type #print steps # fill count_available if not card_type['is_priceless']: # here all prices defined hard, no delays for payment if card_type['slug'] in ('test', 'once'): key = '%s_price' % card_type['slug'] prices = dictlist_keyval(card_type['price_categories'], 'id', steps['price_category'])[0] price = float(prices[key]) steps['price'] = steps['paid'] = price steps['count_sold'] = 1 if float(steps['price']) - float(steps['paid']) < 0.01: # client paid full price steps['count_available'] = steps['count_sold'] else: # need to calculate prices = dictlist_keyval(card_type['price_categories'], 'id', steps['price_category'])[0] price = float(prices['once_price']) from math import floor steps['count_available'] = int(floor(steps['paid'] / price)) # import pprint # print 'STEPS:' # pprint.pprint(steps) # send data to user's model model = self.tableHistory.model() model.insert_new(steps)