def update_line_ok_ko(self, offer_id=None): try: offer = Offer(offer_id) offer.set_lineok_lineko(offer.get_nb_line_ok(), offer.get_nb_line_ko()) return str(Response(Response.SUCCESS_STATUS, Response.SUCCESS_MSG)) except Exception: return str(Response(Response.ERROR_STATUS, traceback.format_exc()))
def add_credit(id_client, id_offer, id_debet, sum): acc = Account.get(Account.ID_account == id_debet) acc.sum += sum acc.save() dateall = date.today() day = dateall.day month = dateall.month year = dateall.year period = (Offer.get(Offer.ID_offer == id_offer)).period percent = (Offer.get(Offer.ID_offer == id_offer)).percent year_period = period // 12 if day == 31: day -= 1 if year_period > 0: year += year_period period -= year_period * 12 if month + period > 12: k = 12 - month period -= k year += 1 month += period if month == 2 & day == 30: day = 28 date_close = datetime(year, month, day) summonth = round(((sum * percent) / (100 * 12)) / (1 - (1 / ((1 + (percent / (100 * 12)))**(period)))), 2) sumcred = summonth * period Account.create(sum=(sumcred * -1), ID_offer=id_offer, ID_client=id_client, date_open=dateall, date_close=date_close)
def remove_offer(self, offer_id=None): if offer_id is None: return str(Response(Response.ERROR_STATUS, "Invalid argument")) try: offer = Offer(offer_id) response = offer.remove() except GraphError as e: response = Response(Response.ERROR_STATUS, traceback.format_exc()) return str(response)
def add_offer(name, percent, type, period): if type == "1": Offer.create(name=name, type='credit', period=period, percent=percent) elif type == "2": Offer.create(name=name, type='deposit', period=period, percent=percent)
def import_set_status(self, table={}): table = json.loads(table) if "offer_id" not in table and "offer_status" not in table: return str(Response(Response.ERROR_STATUS, "Invalid argument")) try: offer_id = table["offer_id"] offer = Offer(offer_id) offer.set_is_active(table["offer_status"]) offer.update_best_price() response = Response(Response.SUCCESS_STATUS, "OK") except GraphError as e: response = Response(Response.ERROR_STATUS, traceback.format_exc()) return str(response)
def remove(self): try: graph = get_graph() query = "MATCH (ko:OfferLineKO)-[r]-(o:Offer) WHERE id(ko) = " + self.id + " DELETE ko,r RETURN id(o)" result = graph.cypher.execute(query) if len(result) != 0: offer_id = result[0].__getattribute__('id(o)') offer = Offer(str(offer_id)) line_ok_number = offer.get_nb_line_ok() line_ko_number = offer.get_nb_line_ko() offer.set_lineok_lineko(line_ok_number, line_ko_number) except Exception as e: return Response(Response.ERROR_STATUS, traceback.format_exc()) return Response(Response.SUCCESS_STATUS, Response.SUCCESS_MSG, len(result))
def publish_offer(self, offer_id=None): if offer_id is None: return str(Response(Response.ERROR_STATUS, "invalid argument")) try: offer = Offer(offer_id) offers_to_disable = OfferDAO.get_offers_from_partner(offer.get_partner()) for it in offers_to_disable: it.set_is_active(False) it.update_best_price() response = offer.publish() offer.update_best_price() except Exception: response = Response(Response.ERROR_STATUS, traceback.format_exc()) return str(response)
def add_deposit(id_client, id_offer, id_debet, sum): dateall = date.today() day = dateall.day month = dateall.month year = dateall.year period = (Offer.get(Offer.ID_offer == id_offer)).period year_period = period // 12 if (day == 31): day -= 1 if year_period > 0: year += year_period period -= year_period * 12 if month + period > 12: k = 12 - month period -= k year += 1 month += period if month == 2 & day == 30: day = 28 date_close = datetime(year, month, day) if ((Account.get(Account.ID_account == id_debet)).sum > sum): Account.create(sum=sum, ID_offer=id_offer, ID_client=id_client, date_open=dateall, date_close=date_close) acc = Account.get(Account.ID_account == id_debet) acc.sum -= sum acc.save() s = 1 return s else: s = 2 return s
def Get_credit(ID_client): id_credit = [] account = Account.select().where((Account.ID_client == ID_client)) for it in account: if Offer.get(Offer.ID_offer == it.ID_offer).type == ('credit'): id_credit.append(it.ID_account) return id_credit
def registration_client(name, surname, patronymic, passport_id, passport_seria, date_of_birth, login, password): dateall = date_of_birth.split('-') day = int(dateall[2]) month = int(dateall[1]) year = int(dateall[0]) if ((passport_id > 1970) & (passport_id < 2030) & (passport_seria > 100000) & (passport_seria < 999999)): Client.create(name=name, surname=surname, patronymic=patronymic, passport_id=passport_id, passport_seria=passport_seria, date_of_birth=date(year, month, day), login=login, password=password) sumR = random.randint(500, 5000) Account.create( sum=sumR, ID_offer=Offer.get(Offer.ID_offer == 1), ID_client=Client.get((Client.passport_seria == passport_seria) & (Client.passport_id == passport_id)), date_open=date.today()) s = 1 return s else: s = 2 return s
def get_offers_from_partner(partner, filter=None): offers = [] try: company = http.request.env['res.company'].search([])[0].name if filter is not None: filter = "AND o.IsActive = true AND o.IsSpot = false " else: filter = "" query = "MATCH (c:Company)-[]-(o:Offer)-[r]-(p:Partner) WHERE lower(c.Name) = lower(\"" + company + "\") AND lower(p.Name) = lower(\"" + partner + "\") " query += filter + "RETURN id(o)" result = get_graph().cypher.execute(query) if len(result) != 0: for it in result: id = str(it.__getattribute__("id(o)")) offers.append(Offer(id)) return offers except Exception as e: _logger().error(traceback.format_exc()) return offers
def publish_offer(self, offer_id=None): if offer_id is None: return str(Response(Response.ERROR_STATUS, "invalid argument")) try: offer = Offer(offer_id) offers_to_disable = OfferDAO.get_offers_from_partner( offer.get_partner()) for it in offers_to_disable: it.set_is_active(False) it.update_best_price() response = offer.publish() offer.update_best_price() except Exception: response = Response(Response.ERROR_STATUS, traceback.format_exc()) return str(response)
def _get_offers_from_company(page, where): try: offers = [] company = http.request.env['res.company'].search([])[0].name query = "MATCH (p:Partner)-[]-(o:Offer)-[r]-(c:Company) WHERE " + where + " AND lower(c.Name) = lower(\"" + company + "\") OPTIONAL MATCH (o)-[]-(f:Files) RETURN id(o) AS id, id(f) AS file_id ORDER BY o.DateOffer DESC SKIP " + str( (page - 1) * OFFERS_PER_PAGE) + " LIMIT " + str(OFFERS_PER_PAGE) result = get_graph().cypher.execute(query) if len(result) != 0: for it in result: offers.append(Offer(str(it.id))) response = {'offers': offers, 'current_page': page} query = "MATCH (p:Partner)-[]-(o:Offer)-[r]-(c:Company) WHERE " + where + " AND lower(c.Name) = lower(\"" + company + "\") OPTIONAL MATCH (o)-[]-(f:Files) RETURN COUNT(o) AS count" count = get_graph().cypher.execute(query).one if count % OFFERS_PER_PAGE == 0: response['page_count'] = count / OFFERS_PER_PAGE else: response['page_count'] = count / OFFERS_PER_PAGE + 1 return response except Exception as e: print traceback.format_exc() return
def delete_offer(id_offer): Offer.get(Offer.ID_offer == id_offer).delete_instance()
def Get_offer_name(id_acc): return Offer.get(Offer.ID_offer == (Account.get( Account.ID_account == id_acc)).ID_offer).name
def bw_import_validation(self, **post): try: if 'file_name' in post: column_list = json.loads(post['table']) file_name = post['file_name'] offer = Offer(post) else: # TODO handle error page return "ERROR" except (ValueError, KeyError, TypeError) as e: # TODO handle error page sys.stderr.write(traceback.format_exc()) return traceback.format_exc() try: home = expanduser("~") + "/" file = open(home + file_name, "rb") file_name = os.path.splitext(file_name)[0] line_ko_file = open(home + file_name + "-KO.csv", "w") line_ok_file = open(home + file_name + "-OK.csv", "w") line_ko = ParsingCsv(line_ko_file) line_ok = ParsingCsv(line_ok_file) parsing_file = ParsingFile(file) if len(parsing_file) == 0: return redirect('/cycom/new_import') res = get_col_list() column_to_check = get_col_to_check() nb_line_ok = 0 nb_line_ko = 0 offer.create() # init de la liste des colonnes qui sera integres dans les csv final_column_list = [] i = 0 for v in column_list: for it in res: if it.name == v.encode("utf-8"): final_column_list.append(it.csv_col.encode("utf-8")) column_list[i] = it.csv_col.encode("utf-8") i += 1 for it in res: if it.to_check: if it.csv_col not in final_column_list: final_column_list.append(it.csv_col) column_list.append(it.csv_col) line_ok.append_line(final_column_list) line_ko.append_line(final_column_list) # Boucle principale de parsing, parcours chaque ligne du fichier d'origine et check chaque ligne parsing_file = parsing_file[:1] for item in parsing_file: i = 0 new_line = [] table = self.init_table_columns(column_list, column_to_check) empty = False for column in column_list: if column != "": value = "-" if i < len(item): it = item[i] if type(it) is unicode: # this delete every useless spaces (end begin and between words it = re.sub( r"\s+", " ", it.encode("utf-8")).strip().lower() it = it.replace('"', "'") it = it.strip().lower() it = self.bw_init_value(it, column_list[i]) if column in column_to_check: table[column.lower()] = it value = it if column == 'Vin' and it == "-": empty = True else: tmp = column.lower() if tmp != "" and tmp in table and table[tmp] != "": value = table[tmp] new_line.append(value) i += 1 if not empty: table_tmp = self.bw_apply_pattern(table, format_pattern) if table_tmp != table: for k, v in table_tmp.iteritems(): for i in range(0, len(final_column_list)): if final_column_list[i] == k: new_line[i] = v response = self.bw_check_line(table_tmp) if response.status == Response.ERROR_STATUS: print traceback.format_exc() return traceback.format_exc() elif response.status == Response.SUCCESS_STATUS and response.size == 0: line_ko.append_line(new_line) nb_line_ko += 1 else: content = response.content for k, v in content.iteritems(): for i in range(0, len(final_column_list)): if final_column_list[i] == k: new_line[i] = v line_ok.append_line(new_line) nb_line_ok += 1 file.close() line_ok_file.close() line_ko_file.close() offer.set_lineok_lineko(nb_line_ok, nb_line_ko) if nb_line_ok != 0: offer.import_csv_ok(file_name + "-OK.csv") if nb_line_ko != 0: offer.import_csv_ko(file_name + "-KO.csv") offer.set_is_loaded(True) except (IOError, GraphError) as e: sys.stderr.write(traceback.format_exc()) offer.remove() return traceback.format_exc() return redirect('/cycom/offer-list')
def bw_import_validation(**post): try: if 'file_name' in post: column_list = json.loads(post['table']) file_name = post['file_name'] offer = Offer(post) else: # TODO handle error page return "ERROR" except (ValueError, KeyError, TypeError) as e: # TODO handle error page sys.stderr.write(traceback.format_exc()) return traceback.format_exc() try: home = expanduser("~") + "/" file = open(home + file_name, "rb") file_name = os.path.splitext(file_name)[0] line_ko_file = open(home + file_name + "-KO.csv", "w") line_ok_file = open(home + file_name + "-OK.csv", "w") line_ko = ParsingCsv(line_ko_file) line_ok = ParsingCsv(line_ok_file) parsing_file = ParsingFile(file) if len(parsing_file) == 0: return redirect('/cycom/new_import') res = get_col_list() column_to_check = get_col_to_check() nb_line_ok = 0 nb_line_ko = 0 offer.create() # init de la liste des colonnes qui sera integres dans les csv final_column_list = [] i = 0 for v in column_list: for it in res: if it.name == v.encode("utf-8"): final_column_list.append(it.csv_col.encode("utf-8")) column_list[i] = it.csv_col.encode("utf-8") i += 1 for it in res: if it.to_check: if it.csv_col not in final_column_list: final_column_list.append(it.csv_col) column_list.append(it.csv_col) line_ok.append_line(final_column_list) line_ko.append_line(final_column_list) # Boucle principale de parsing, parcours chaque ligne du fichier d'origine et check chaque ligne parsing_file = parsing_file[:1] for item in parsing_file: i = 0 new_line = [] table = self.init_table_columns(column_list, column_to_check) empty = False for column in column_list: if column != "": value = "-" if i < len(item): it = item[i] if type(it) is unicode: # this delete every useless spaces (end begin and between words it = re.sub(r"\s+", " ", it.encode("utf-8")).strip().lower() it = it.replace('"', "'") it = it.strip().lower() it = self.bw_init_value(it, column_list[i]) if column in column_to_check: table[column.lower()] = it value = it if column == 'Vin' and it == "-": empty = True else: tmp = column.lower() if tmp != "" and tmp in table and table[tmp] != "": value = table[tmp] new_line.append(value) i += 1 if not empty: table_tmp = self.bw_apply_pattern(table, format_pattern) if table_tmp != table: for k, v in table_tmp.iteritems(): for i in range(0, len(final_column_list)): if final_column_list[i] == k: new_line[i] = v response = self.bw_check_line(table_tmp) if response.status == Response.ERROR_STATUS: print traceback.format_exc() return traceback.format_exc() elif response.status == Response.SUCCESS_STATUS and response.size == 0: line_ko.append_line(new_line) nb_line_ko += 1 else: content = response.content for k, v in content.iteritems(): for i in range(0, len(final_column_list)): if final_column_list[i] == k: new_line[i] = v line_ok.append_line(new_line) nb_line_ok += 1 file.close() line_ok_file.close() line_ko_file.close() offer.set_lineok_lineko(nb_line_ok, nb_line_ko) if nb_line_ok != 0: offer.import_csv_ok(file_name + "-OK.csv") if nb_line_ko != 0: offer.import_csv_ko(file_name + "-KO.csv") offer.set_is_loaded(True) except (IOError, GraphError) as e: sys.stderr.write(traceback.format_exc()) offer.remove() return traceback.format_exc() return redirect('/cycom/offer-list')
def Get_percent(id_acc): return Offer.get(Offer.ID_offer == (Account.get( Account.ID_account == id_acc)).ID_offer).percent
def change_offer(id_offer, name, period, percent): offer = Offer.get(Offer.ID_offer == id_offer) offer.name = name offer.percent = percent offer.period = period offer.save()
def add_debet(id_client): Account.create(sum=0, ID_offer=Offer.get(Offer.ID_offer == 1), ID_client=id_client, date_open=date.today())
def Get_offer(): return Offer.select()
def Get_deposit_offer(): return Offer.select().where(Offer.type == 'deposit')
def Get_credit_offer(): return Offer.select().where(Offer.type == 'credit')