def add_quan_lines_ids_to_poster_theo_siteleech_id(self): for c, r in enumerate(self.env['bds.poster'].search([])): product_category_query_siteleech =\ '''select count(quan_id),quan_id,min(gia),avg(gia),max(gia),siteleech_id from bds_bds where poster_id = %s group by quan_id,siteleech_id'''%r.id product_category_query_no_siteleech = \ '''select count(quan_id),quan_id,min(gia),avg(gia),max(gia) from bds_bds where poster_id = %s group by quan_id'''%r.id a = { 'product_category_query_siteleech': product_category_query_siteleech, 'product_category_query_no_siteleech': product_category_query_no_siteleech } for k, product_category_query in a.items(): self.env.cr.execute(product_category_query) product_category = self.env.cr.fetchall() #print product_category for tuple_count_quan in product_category: quan_id = int(tuple_count_quan[1]) if k == 'product_category_query_no_siteleech': siteleech_id = False else: siteleech_id = int(tuple_count_quan[5]) g_or_c_ss( self, 'bds.quanofposter', { 'quan_id': quan_id, 'poster_id': r.id, 'siteleech_id': siteleech_id }, { 'quantity': tuple_count_quan[0], 'min_price': tuple_count_quan[2], 'avg_price': tuple_count_quan[3], 'max_price': tuple_count_quan[4], }, True)
def add_quan_lines_ids_to_poster(self): for c, r in enumerate(self.env['bds.poster'].search([])): #print 'hadling...one usee' ,c product_category_query =\ '''select count(quan_id),quan_id,min(gia),avg(gia),max(gia) from bds_bds where poster_id = %s group by quan_id'''%r.id self.env.cr.execute(product_category_query) product_category = self.env.cr.fetchall() #print product_category for tuple_count_quan in product_category: quan_id = int(tuple_count_quan[1]) #quantity = int(tuple_count_quan[0].replace('L','')) quan = self.env['bds.quan'].browse(quan_id) if quan.name in [ u'Quận 1', u'Quận 3', u'Quận 5', u'Quận 10', u'Tân Bình' ]: for key1 in ['count', 'avg']: if key1 == 'count': value = tuple_count_quan[0] elif key1 == 'avg': value = tuple_count_quan[3] name = quan.name_unidecode.replace('-', '_') name = key1 + '_' + name setattr(r, name, value) #print 'set attr',name,value g_or_c_ss(self, 'bds.quanofposter', { 'quan_id': quan_id, 'poster_id': r.id }, { 'quantity': tuple_count_quan[0], 'min_price': tuple_count_quan[2], 'avg_price': tuple_count_quan[3], 'max_price': tuple_count_quan[4], }, True)
def quanofposter_ids_(self): # return True for r in self: print('quanofposter_ids_**** r.id', r.id) if r.id: # print ('ahahah',r.id) quanofposter_ids_lists = [] product_category_query_siteleech =\ '''select count(quan_id),quan_id, min(gia), avg(gia), max(gia), siteleech_id from bds_bds where poster_id = %s and gia > 0 group by quan_id,siteleech_id'''%r.id product_category_query_no_siteleech = \ '''select count(quan_id),quan_id,min(gia),avg(gia),max(gia) from bds_bds where poster_id = %s and gia > 0 group by quan_id'''%r.id all_site_all_quan = \ '''select count(quan_id),min(gia), avg(gia), max(gia) from bds_bds where poster_id = %s and gia > 0 '''%r.id a = { 'product_category_query_siteleech': product_category_query_siteleech, 'product_category_query_no_siteleech': product_category_query_no_siteleech, 'all_site_all_quan': all_site_all_quan, } for k, product_category_query in a.items(): self.env.cr.execute(product_category_query) quan_va_gia_fetchall = self.env.cr.fetchall() for tuple_count_quan in quan_va_gia_fetchall: offset = 0 if k == 'all_site_all_quan': siteleech_id = False quan_id = False offset = 1 elif k == 'product_category_query_no_siteleech': siteleech_id = False quan_id = int(tuple_count_quan[1]) else: quan_id = int(tuple_count_quan[1]) siteleech_id = int(tuple_count_quan[5]) quanofposter = g_or_c_ss( self, 'bds.quanofposter', { 'quan_id': quan_id, 'poster_id': r.id, 'siteleech_id': siteleech_id }, { 'quantity': tuple_count_quan[0], 'min_price': tuple_count_quan[2 - offset], 'avg_price': tuple_count_quan[3 - offset], 'max_price': tuple_count_quan[4 - offset], }, True) quanofposter_ids_lists.append( quanofposter.id) #why???? if siteleech_id == False: r.min_price = tuple_count_quan[2 - offset] r.avg_price = tuple_count_quan[3 - offset] r.max_price = tuple_count_quan[4 - offset] r.quanofposter_ids = quanofposter_ids_lists
def siteleech_id_(self): for r in self: if r.url: if 'chotot' in r.url: name = 'chotot' elif 'batdongsan' in r.url: name = 'batdongsan' else: name = re.search('\.(.*?)\.', r.url).group(1) chottot_site = g_or_c_ss(self, 'bds.siteleech', {'name': name}) r.siteleech_id = chottot_site.id
def worker(self, thread_index, url_id, thread_number): new_cr = sql_db.db_connect(self.env.cr.dbname).cursor() uid, context = self.env.uid, self.env.context with api.Environment.manage(): self.env = api.Environment(new_cr, uid, context) luong = g_or_c_ss(self, 'bds.luong', { 'threadname': str(1), 'url_id': url_id }) if luong[0].current_page == 0: current_page = thread_index else: current_page = luong[0].current_page + thread_number luong[0].write({'current_page': current_page}) new_cr.commit() self.env.cr.close()
def quanofposter_ids_(self): for r in self: quanofposter_ids_lists = [] product_category_query_siteleech =\ '''select count(quan_id),quan_id,min(gia),avg(gia),max(gia),siteleech_id from bds_bds where poster_id = %s group by quan_id,siteleech_id'''%r.id product_category_query_no_siteleech = \ '''select count(quan_id),quan_id,min(gia),avg(gia),max(gia) from bds_bds where poster_id = %s group by quan_id'''%r.id a = { 'product_category_query_siteleech': product_category_query_siteleech, 'product_category_query_no_siteleech': product_category_query_no_siteleech } for k, product_category_query in a.items(): self.env.cr.execute(product_category_query) quan_va_gia_fetchall = self.env.cr.fetchall() # #print 'count(quan_id) %s,quan_id %s,min(gia) %s ,avg(gia) %s,max(gia) %s,siteleech_id %s' %*quan_va_gia_fetchall # #print 'count(quan_id) %s,quan_id %s,min(gia) %s ,avg(gia) %s,max(gia) %s,siteleech_id %s' %*quan_va_gia_fetchall # #print 'quan_va_gia_fetchall',quan_va_gia_fetchall for tuple_count_quan in quan_va_gia_fetchall: quan_id = int(tuple_count_quan[1]) if k == 'product_category_query_no_siteleech': siteleech_id = False else: siteleech_id = int(tuple_count_quan[5]) quanofposter = g_or_c_ss( self, 'bds.quanofposter', { 'quan_id': quan_id, 'poster_id': r.id, 'siteleech_id': siteleech_id }, { 'quantity': tuple_count_quan[0], 'min_price': tuple_count_quan[2], 'avg_price': tuple_count_quan[3], 'max_price': tuple_count_quan[4], }, True) quanofposter_ids_lists.append(quanofposter.id) #why???? if siteleech_id == False: r.min_price = tuple_count_quan[2] r.avg_price = tuple_count_quan[3] r.max_price = tuple_count_quan[4] r.quanofposter_ids = quanofposter_ids_lists