def _import_infos(self, cr, uid, data, context): dog_obj=pooler.get_pool(cr.dbname).get('labo.dog') content=base64.decodestring(data['form']['attach']) xl = tools.readexcel(file_contents = content) shname = xl.worksheets() c=[] sheetnames=[] for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) for lines in sheetnames: for line in lines: if line['LPCNPR']: dog_id=dog_obj.search(cr,uid,[('progenus_number','=',line['LPCNPR'])]) if len(dog_id): c.append(dog_id[0]) dog_obj.write(cr,uid,dog_id[0],{'name':line['LPCNOM'] and line['LPCNOM'].strip() or None, 'origin':line['LPCNOR'] and line['LPCNOR'].strip() or None }) return { 'domain': "[('id','in', ["+','.join(map(str,c))+"])]", 'name': 'My modified dogs', 'view_type': 'form', 'view_mode': 'tree,form', 'res_model': 'labo.dog', 'view_id': False, 'type': 'ir.actions.act_window' } return {}
def _import_infos(self, cr, uid, data, context): dog_obj = pooler.get_pool(cr.dbname).get('labo.dog') content = base64.decodestring(data['form']['attach']) xl = tools.readexcel(file_contents=content) shname = xl.worksheets() c = [] sheetnames = [] for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) for lines in sheetnames: for line in lines: if line['LPCNPR']: dog_id = dog_obj.search( cr, uid, [('progenus_number', '=', line['LPCNPR'])]) if len(dog_id): c.append(dog_id[0]) dog_obj.write( cr, uid, dog_id[0], { 'name': line['LPCNOM'] and line['LPCNOM'].strip() or None, 'origin': line['LPCNOR'] and line['LPCNOR'].strip() or None }) return { 'domain': "[('id','in', [" + ','.join(map(str, c)) + "])]", 'name': 'My modified dogs', 'view_type': 'form', 'view_mode': 'tree,form', 'res_model': 'labo.dog', 'view_id': False, 'type': 'ir.actions.act_window' } return {}
def import_attachment(self, cr, uid, data, context): fields ={#'mission_number':False, 'dog_child': False, 'lp_file':False, 'lp_serv':False, 'lp_doss':False, 'dog_mother': False, 'dog_father': False, 'preleveur1_id':False, # 'preleveur2_id':False, 'sample_id':False, 'res_filiation':False, } fields_prelev = ['name', 'code'] labo_obj = pooler.get_pool(cr.dbname).get('labo.labo') req_obj = pooler.get_pool(cr.dbname).get('labo.analysis.request') sample_obj = pooler.get_pool(cr.dbname).get('labo.sample') dog_obj = pooler.get_pool(cr.dbname).get('labo.dog') partner_obj = pooler.get_pool(cr.dbname).get('res.partner') contact_obj = pooler.get_pool(cr.dbname).get('res.partner.address') flag = '' content = base64.decodestring(data['form']['attach']) sheetnames = [] if data['form']['file_type'] == 'xls': xl = tools.readexcel(file_contents=content) shname = xl.worksheets() for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) # else: # sh1 = csv.DictReader(content.split('\n'), delimiter=',') # csv_lines = [] # for row in sh1: # csv_lines.append(row) # sheetnames.append(csv_lines) # """ # Following code is used for Extracting Data from Excel Files the using xlrd # """ # content=base64.decodestring(data['form']['attach']) # xl = tools.readexcel(file_contents = content) # sheetnames = xl.worksheets() # # """ # Following code is used for the Importing a data from excel sheets to Labo Sample model # Its support multiple sheets also # """ for sheet in sheetnames: for line in sheet: """ Set the labo. sample fields first ... 'LPSERV':'lp_serv', 'LPDOSS':'lp_doss', 'LPCFIL':'res_filiation', 'LPFILE':'lp_file', 'LPDTRC':'date_reception', """ fields['lp_serv'] = row_field(line, 'LPSERV') fields['lp_doss'] = row_field(line, 'LPDOSS') fields['res_filiation'] = row_field(line, 'LPCFIL') fields['lp_file'] = row_field(line, 'LPFILE') fields['date_reception'] = row_field_date(line, 'LPDTRC') # """ # Set the preleveur2_id # """ # # prelver2 = row_field(line,'LPENO2') # if prelver2: # prelev_id2=partner_obj.search(cr, uid, [('name', 'like', prelver2)]) # if len(prelev_id2): # fields['preleveur2_id']=prelev_id2[0] # else: # fields['preleveur2_id'] = partner_obj.create(cr,uid,{'name': prelver2}) # """ Set the preleveur1_id """ prelver1 = row_field(line, 'LPENOM') if prelver2: prelev_id = partner_obj.search(cr, uid, [('name', 'like', prelver1)]) if len(prelev_id): fields['preleveur1_id'] = prelev_id[0] else: fields['preleveur1_id'] = partner_obj.create( cr, uid, { 'name': row_field(line, 'LPENOM'), 'ref': row_field(line, 'LPENUM') }) city_zip = row_field(line, 'LPELOC').split(' ') zip = city_zip[0] and city_zip[0] or '' city = len( city_zip) == 2 and city_zip[1] and city_zip[1:] or '' new_contact_prelev = contact_obj.create( cr, uid, { 'name': row_field(line, 'LPENOM'), 'city': city and city[0].replace('"', ''), 'street': row_field(line, 'LPEADR'), 'zip': zip and zip.replace('"', ''), 'partner_id': new_prelev }) """ Set the Mother dog to labo sample 'LPFNOM':'dog_mother/name', 'LPFNUM':'dog_mother/pedigree', 'LPFTAT':'dog_mother/tatoo', 'LPFPUC':'dog_mother/ship', 'LPFNOR':'dog_mother/origin', 'LPFDTN':'dog_mother/birthdate', 'LPFRLB':'dog_mother/labo_id/ref', 'LPFLLB':'dog_mother/labo_id/name', 'LPFNLB':'dog_mother/labo_id/code', 'LPFNPR':'dog_mother/progenus_number', """ mothername = row_field(line, 'LPFNOM') if mothername: mother = 0 mother_ids = dog_obj.search(cr, uid, [('name', 'like', mothername)]) if mother_ids: mother = mother_ids[0] else: labo_ids = labo_obj.search( cr, uid, [('code', '=', row_field(line, 'LPFNLB'))]) if labo_ids: mother = dog_obj.create( cr, uid, { 'name': row_field(line, 'LPFNOM'), 'progenus_number': row_field(line, 'LPFNPR'), 'origin': row_field(line, 'LPFNOR'), 'tatoo': row_field(line, 'LPFTAT'), 'sex': 'f', 'race': row_field(line, 'LPRACE'), 'birthdate': row_field_date(line, 'LPFDTN'), 'ship': row_field(line, 'LPFPUC'), 'pedigree': row_field(line, 'LPFNUM'), 'labo_id': labo_ids[0] }) else: new_labo_f = 0 if row_field(line, 'LPFLLB') and row_field( line, 'LPFNLB'): new_labo_f = labo_obj.create( cr, uid, { 'name': row_field(line, 'LPFLLB'), 'ref': row_field(line, 'LPFRLB'), 'code': row_field(line, 'LPFNLB'), }) mother = dog_obj.create( cr, uid, { 'name': row_field(line, 'LPFNOM'), 'progenus_number': row_field(line, 'LPFNPR'), 'origin': row_field(line, 'LPFNOR'), 'tatoo': row_field(line, 'LPFTAT'), 'sex': 'f', 'race': row_field(line, 'LPRACE'), 'birthdate': row_field_date(line, 'LPFDTN'), 'ship': row_field(line, 'LPFPUC'), 'pedigree': row_field(line, 'LPFNUM'), 'labo_id': new_labo_f, }) fields['dog_mother'] = mother """ Set the Father dog to labo sample 'LPMNOM':'dog_father/name', 'LPMNUM':'dog_father/pedigree', 'LPMTAT':'dog_father/tatoo', 'LPMPUC':'dog_father/ship', 'LPMNOR':'dog_father/origin', 'LPMDTN':'dog_father/birthdate', 'LPMRLB':'dog_father/labo_id/ref', 'LPMLLB':'dog_father/labo_id/name', 'LPMNLB':'dog_father/labo_id/code', 'LPMNPR':'dog_father/progenus_number', """ fathername = row_field(line, 'LPMNOM') if fathername: father = 0 father_ids = dog_obj.search(cr, uid, [('name', 'like', fathername)]) if father_ids: father = father_ids[0] else: labo_ids = labo_obj.search( cr, uid, [('code', '=', row_field(line, 'LPMNLB'))]) if labo_ids: father = dog_obj.create( cr, uid, { 'name': row_field(line, 'LPMNOM'), 'progenus_number': row_field(line, 'LPMNPR'), 'origin': row_field(line, 'LPMNOR'), 'tatoo': row_field(line, 'LPMTAT'), 'sex': 'M', 'race': row_field(line, 'LPRACE'), 'birthdate': row_field_date(line, 'LPMDTN'), 'ship': row_field(line, 'LPMPUC'), 'pedigree': row_field(line, 'LPMNUM'), 'labo_id': labo_ids[0], }) else: new_labo_m = 0 if row_field(line, 'LPMLLB') and row_field( line, 'LPMNLB'): new_labo_m = labo_obj.create( cr, uid, { 'name': row_field(line, 'LPMLLB'), 'ref': row_field(line, 'LPMRLB'), 'code': row_field(line, 'LPMNLB'), }) father = dog_obj.create( cr, uid, { 'name': row_field(line, 'LPMNOM'), 'progenus_number': row_field(line, 'LPMNPR'), 'origin': row_field(line, 'LPMNOR'), 'tatoo': row_field(line, 'LPMTAT'), 'sex': 'M', 'race': row_field(line, 'LPRACE'), 'birthdate': row_field_date(line, 'LPMDTN'), 'ship': row_field(line, 'LPMPUC'), 'pedigree': row_field(line, 'LPMNUM'), 'labo_id': new_labo_m, }) fields['dog_father'] = father """ Set the Child dog to labo sample 'LPCSEX':'dog_child/sex', 'LPCTAT':'dog_child/tatoo', 'LPCPUC':'dog_child/ship', 'LPCDTN':'dog_child/birthdate', 'LPCNPR':'dog_child/progenus_number', 'LPRACE':'dog_child/race', 'LPSEQ':'dog_child/seq', """ child_prog_number = row_field(line, 'LPCNPR') if child_prog_number: child = 0 child_ids = dog_obj.search( cr, uid, [('progenus_number', 'like', child_prog_number)]) if child_ids: child = child_ids[0] else: labo_ids = labo_obj.search(cr, uid, [('code', '=', 1)]) if labo_ids: child = dog_obj.create( cr, uid, { 'name': row_field(line, 'LPCNPR'), 'progenus_number': row_field(line, 'LPCNPR'), #'origin':row_field(line,'LPMNOR'), 'tatoo': row_field(line, 'LPCTAT'), 'sex': row_field(line, 'LPCSEX'), 'race': row_field(line, 'LPRACE'), 'birthdate': row_field_date(line, 'LPCDTN'), 'ship': row_field(line, 'LPCPUC'), 'seq': row_field(line, 'LPSEQ'), 'labo_id': labo_ids[0], 'parent_m_id': mother, 'parent_f_id': father, }) else: new_labo_c = labo_obj.create(cr, uid, { 'name': 'Progenus', 'ref': '1', 'code': '1', }) child = dog_obj.create( cr, uid, { 'name': row_field(line, 'LPCNPR'), 'progenus_number': row_field(line, 'LPCNPR'), #'origin':row_field(line,'LPMNOR'), 'tatoo': row_field(line, 'LPCTAT'), 'sex': row_field(line, 'LPCSEX'), 'race': row_field(line, 'LPRACE'), 'birthdate': row_field_date(line, 'LPCDTN'), 'ship': row_field(line, 'LPCPUC'), 'seq': row_field(line, 'LPSEQ'), 'labo_id': new_labo_c, 'parent_m_id': mother, 'parent_f_id': father, }) fields['dog_child'] = child type_id = pooler.get_pool( cr.dbname).get('labo.analysis.type').search( cr, uid, [('code', 'ilike', 'EMPDOG')]) type_id_s = type_id and type_id[0] if row_field(line, 'LPNRAP') and flag != row_field(line, 'LPNRAP'): res = row_field(line, 'LPNRAP').split('/') num = ",".join([str(x) for x in res[1:] if x]).replace('"', '').replace(',', '') request_id = req_obj.create(cr, uid, { 'type_id': type_id_s, 'name': num }) flag = row_field(line, 'LPNRAP') else: has_id = req_obj.search(cr, uid, [('type_id', '=', type_id_s)]) request_id = has_id and has_id[0] if not len(has_id): request_id = pooler.get_pool( cr.dbname).get('labo.analysis.request').create( cr, uid, { 'type_id': type_id_s, 'name': 'to_set' }) fields['sample_id'] = request_id sample_id = sample_obj.create(cr, uid, fields) return {}
def _import_attach(self, cr, uid, data, context): list_alpha=['A01','B01','C01','D01','E01','F01','G01','H01', 'A02','B02','C02','D02','E02','F02','G02','H02', 'A03','B03','C03','D03','E03','F03','G03','H03', 'A04','B04','C04','D04','E04','F04','G04','H04', 'A05','B05','C05','D05','E05','F05','G05','H05', 'A06','B06','C06','D06','E06','F06','G06','H06', 'A07','B07','C07','D07','E07','F07','G07','H07', 'A08','B08','C08','D08','E08','F08','G08','H08', 'A09','B09','C09','D09','E09','F09','G09','H09', 'A10','B10','C10','D10','E10','F10','G10','H10', 'A11','B11','C11','D11','E11','F11','G11','H11', 'A12','B12','C12','D12','E12','F12','G12','H12' ] c=pooler.get_pool(cr.dbname).get('labo.sample').get_view_context(cr,uid,context) content=base64.decodestring(data['form']['attach']) list= content.split('\n')[1:] xl = tools.readexcel(file_contents = content) shname = xl.worksheets() sheetnames=[] # fields ={'progenus_number':False,'num_alpha':False} if shname: sh=shname[0] a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) req_obj=pooler.get_pool(cr.dbname).get('labo.analysis.request') sample_obj=pooler.get_pool(cr.dbname).get('labo.sample') labo_setup_obj=pooler.get_pool(cr.dbname).get('labo.setup') setup_obj=pooler.get_pool(cr.dbname).get('analysis.setup') setup_hist_obj=pooler.get_pool(cr.dbname).get('setup.history') dog_obj=pooler.get_pool(cr.dbname).get('labo.dog') user_obj=pooler.get_pool(cr.dbname).get('res.users') view_b=sample_obj.browse(cr,uid,data['ids'])[0] view_type=view_b.cont if not view_type: view_type=view_b.sample_id.type_id.code flag='' flag1='' a_set_ids=[] user_id='' for lines in sheetnames: first_lines=lines[:5] last_lines=lines[11:] a=first_lines[0].keys() set_up_n=a[0]!='F1' and a[0] or '' page_number=first_lines[0].values()[0] x1=first_lines[1].values()[0] date_f=first_lines[2].values()[0] operat=first_lines[3].values()[0] if operat: user_ids=user_obj.search(cr,uid,[('login','=',operat)]) if user_ids: user_id = user_ids and user_ids[0] or None #continue till the 5th columns set_up_ids=labo_setup_obj.search(cr,uid,[('name','=',page_number)]) set_up_id = set_up_ids and set_up_ids[0] if not set_up_id :#and flag!=page_number: flag=page_number set_up_id=labo_setup_obj.create(cr,uid,{'name':page_number, 'date_s':date_f}) # #search analysis setup # a_set_ids=setup_obj.search(cr,uid,[('set_up','=',set_up_id)]) # a_set_id=a_set_ids and a_set_ids[0] or '' # if not len(a_set_ids):# and flag1!=set_up_id: # a_set_id=setup_obj.create(cr,uid,{'set_up':set_up_id, 'well':c.index(a.values()[1])}) for i in last_lines: prog=str(i.values()[0]) try: t=list_alpha.index(i.values()[1].upper()) except: raise wizard.except_wizard("Error!", "Please, Check the value '%s' in your file" %i.values()[1]) a_set_ids=setup_obj.search(cr,uid,[('set_up','=',set_up_id), ('well','=',list_alpha.index(i.values()[1].upper())+1 )]) a_set_id=a_set_ids and a_set_ids[0] or '' if not len(a_set_ids): a_set_id=setup_obj.create(cr,uid,{'set_up':set_up_id, 'well':list_alpha.index(i.values()[1])+1, 'run_setup': None }) if view_type!='EMPDOG' and view_type!='EMPDOG_2' and view_type!='EMPCHE' and prog: cr.execute("select id from labo_sample where progenus_number = '%s'"%(prog)) res2=cr.fetchall() li=[] for l in res2: li.append(l[0]) for r in li: c=sample_obj.browse(cr,uid,r) # if user_id: # sample_obj.write(cr,uid,c.id,{'user_id':user_id}) #ADD HISTORY if c.file_setup and c.file_setup.set_up and c.file_setup.set_up.name and (c.file_setup.set_up.name!=str(page_number)): r=setup_hist_obj.create(cr,uid,{'name':time.strftime('%Y-%m-%d'), 'sample_id':c.id, 'old_alpha':c.num_alpha, 'setup_id2':c.file_setup.set_up.id or '', 'setup_id': a_set_id #or None }) k=sample_obj.write(cr,uid,c.id,{'num_alpha':i.values()[1], 'file_setup':a_set_id, 'state': 'ko' }) elif view_type in ('EMPDOG','EMPDOG_2','EMPCHE') and prog : cr.execute("select d.id from labo_dog d where d.progenus_number = '%s' "%(prog)) # cr.execute("select l.id from labo_dog d,labo_sample l,labo_plate p where d.progenus_number = '%s' and (l.dog_child=d.id or l.dog_father=d.id or l.dog_mother=d.id)"%(prog)) res1=cr.fetchall() li=[] for l in res1: li.append(l[0]) for r in li: c=dog_obj.browse(cr,uid,r) # if user_id: # dog_obj.write(cr,uid,c.id,{'user_id':user_id}) #ADD HISTORY if c.file_setup and c.file_setup.set_up and c.file_setup.set_up.name and (c.file_setup.set_up.name!=str(page_number)): z=setup_hist_obj.create(cr,uid,{'name':time.strftime('%Y-%m-%d'), 'dog_id1':c.id, 'setup_id2':c.file_setup.set_up.id or '', 'old_alpha':c.num_alpha, 'setup_id': a_set_id }) k=dog_obj.write(cr,uid,c.id,{'num_alpha':i.values()[1], 'file_setup':a_set_id, 'state':'ko', }) return {}
def _import_attach_plate(self, cr, uid, data, context): content=base64.decodestring(data['form']['attach']) list= content.split('\n')[1:] xl = tools.readexcel(file_contents = content) shname = xl.worksheets() sheetnames=[] for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) req_obj=pooler.get_pool(cr.dbname).get('labo.analysis.request') sample_obj=pooler.get_pool(cr.dbname).get('labo.sample') dog_obj=pooler.get_pool(cr.dbname).get('labo.dog') user_obj=pooler.get_pool(cr.dbname).get('res.users') labo_plate_obj=pooler.get_pool(cr.dbname).get('labo.plate') plate_hist_obj=pooler.get_pool(cr.dbname).get('plate.history') setup_obj=pooler.get_pool(cr.dbname).get('analysis.setup') view_b=sample_obj.browse(cr,uid,data['ids'])[0] view_type=view_b.cont if not view_type: view_type=view_b.sample_id.type_id.code flag='' flag1='' a_set_ids=[] user_id='' for lines in sheetnames: first_lines=lines[:5] last_lines=lines[9:] a=first_lines[0].keys() set_up_n=a[0]!='F1' and a[0] or '' page_number=str(first_lines[0].values()[0]).zfill(4) x1=first_lines[1].values()[0] date_f=first_lines[2].keys()[0] operat=first_lines[1].values()[0] if operat: user_ids=user_obj.search(cr,uid,[('login','=',operat)]) if user_ids: user_id = user_ids and user_ids[0] or None #continue till the 5th columns plate_ids=labo_plate_obj.search(cr,uid,[('name','=',page_number)]) plate_id = plate_ids and plate_ids[0] if not plate_id : plate_id=labo_plate_obj.create(cr,uid,{'name':page_number, 'date_p':date_f or None}) for i in last_lines: prog=unicode(i.values()[0]).encode('utf8')#.decode('latin1') if view_type!='EMPDOG' and view_type!='EMPDOG_2' and view_type!='EMPCHE': cr.execute("select id from labo_sample where progenus_number = '%s'"%(prog)) res=cr.fetchall() #ADD HISTORY li=[] for il in res: if il[0]: li.append(il[0]) for r in li: curr_sample=sample_obj.browse(cr,uid,r) if curr_sample and curr_sample.plate_id and (curr_sample.plate_id.name!=page_number): jj=plate_hist_obj.create(cr,uid,{'name':time.strftime('%Y-%m-%d'), 'sample_id':r, 'plate_id2':curr_sample.plate_id.id, 'plate_id': plate_id }) k=sample_obj.write(cr,uid,r,{'num_alpha2':i.values()[1], 'plate_id':plate_id, }) sample_obj.write(cr,uid,r,{'user_id':user_id or None, 'state': 'ko'}) else: #cr.execute("select l.id from labo_dog d,labo_sample l,labo_plate p where d.progenus_number = '%s' and l.plate_id=p.id and p.name='%s'"%(prog,page_number)) # cr.execute("select l.id from labo_dog d,labo_sample l,labo_plate p where d.progenus_number = '%s' and (l.dog_child=d.id or l.dog_father=d.id or l.dog_mother=d.id)"%(prog)) cr.execute("select d.id from labo_dog d where d.progenus_number = '%s' "%(prog)) res=cr.fetchall() li=[] for il in res: if il[0]: li.append(il[0]) for r in li: curr_dog=dog_obj.browse(cr,uid,r) if curr_dog and curr_dog.plate_id and (curr_dog.plate_id.name!=page_number): jj=plate_hist_obj.create(cr,uid,{'name':time.strftime('%Y-%m-%d'), 'dog_id1':r, 'old_alpha':curr_dog.num_alpha2, 'plate_id2':curr_dog.plate_id.id, 'plate_id': plate_id }) k=dog_obj.write(cr,uid,r,{'num_alpha2':i.values()[1], 'plate_id':plate_id, }) sample_obj.write(cr,uid,r,{'user_id':user_id or None, 'state': 'ko'}) return {}
def import_attachment(self, cr, uid, data, context): fields = { #'mission_number':False, "dog_child": False, "lp_file": False, "lp_serv": False, "lp_doss": False, "dog_mother": False, "dog_father": False, "preleveur1_id": False, # 'preleveur2_id':False, "sample_id": False, "res_filiation": False, } fields_prelev = ["name", "code"] labo_obj = pooler.get_pool(cr.dbname).get("labo.labo") req_obj = pooler.get_pool(cr.dbname).get("labo.analysis.request") sample_obj = pooler.get_pool(cr.dbname).get("labo.sample") dog_obj = pooler.get_pool(cr.dbname).get("labo.dog") partner_obj = pooler.get_pool(cr.dbname).get("res.partner") contact_obj = pooler.get_pool(cr.dbname).get("res.partner.address") flag = "" content = base64.decodestring(data["form"]["attach"]) sheetnames = [] if data["form"]["file_type"] == "xls": xl = tools.readexcel(file_contents=content) shname = xl.worksheets() for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) # else: # sh1 = csv.DictReader(content.split('\n'), delimiter=',') # csv_lines = [] # for row in sh1: # csv_lines.append(row) # sheetnames.append(csv_lines) # """ # Following code is used for Extracting Data from Excel Files the using xlrd # """ # content=base64.decodestring(data['form']['attach']) # xl = tools.readexcel(file_contents = content) # sheetnames = xl.worksheets() # # """ # Following code is used for the Importing a data from excel sheets to Labo Sample model # Its support multiple sheets also # """ for sheet in sheetnames: for line in sheet: """ Set the labo. sample fields first ... 'LPSERV':'lp_serv', 'LPDOSS':'lp_doss', 'LPCFIL':'res_filiation', 'LPFILE':'lp_file', 'LPDTRC':'date_reception', """ fields["lp_serv"] = row_field(line, "LPSERV") fields["lp_doss"] = row_field(line, "LPDOSS") fields["res_filiation"] = row_field(line, "LPCFIL") fields["lp_file"] = row_field(line, "LPFILE") fields["date_reception"] = row_field_date(line, "LPDTRC") # """ # Set the preleveur2_id # """ # # prelver2 = row_field(line,'LPENO2') # if prelver2: # prelev_id2=partner_obj.search(cr, uid, [('name', 'like', prelver2)]) # if len(prelev_id2): # fields['preleveur2_id']=prelev_id2[0] # else: # fields['preleveur2_id'] = partner_obj.create(cr,uid,{'name': prelver2}) # """ Set the preleveur1_id """ prelver1 = row_field(line, "LPENOM") if prelver2: prelev_id = partner_obj.search(cr, uid, [("name", "like", prelver1)]) if len(prelev_id): fields["preleveur1_id"] = prelev_id[0] else: fields["preleveur1_id"] = partner_obj.create( cr, uid, {"name": row_field(line, "LPENOM"), "ref": row_field(line, "LPENUM")} ) city_zip = row_field(line, "LPELOC").split(" ") zip = city_zip[0] and city_zip[0] or "" city = len(city_zip) == 2 and city_zip[1] and city_zip[1:] or "" new_contact_prelev = contact_obj.create( cr, uid, { "name": row_field(line, "LPENOM"), "city": city and city[0].replace('"', ""), "street": row_field(line, "LPEADR"), "zip": zip and zip.replace('"', ""), "partner_id": new_prelev, }, ) """ Set the Mother dog to labo sample 'LPFNOM':'dog_mother/name', 'LPFNUM':'dog_mother/pedigree', 'LPFTAT':'dog_mother/tatoo', 'LPFPUC':'dog_mother/ship', 'LPFNOR':'dog_mother/origin', 'LPFDTN':'dog_mother/birthdate', 'LPFRLB':'dog_mother/labo_id/ref', 'LPFLLB':'dog_mother/labo_id/name', 'LPFNLB':'dog_mother/labo_id/code', 'LPFNPR':'dog_mother/progenus_number', """ mothername = row_field(line, "LPFNOM") if mothername: mother = 0 mother_ids = dog_obj.search(cr, uid, [("name", "like", mothername)]) if mother_ids: mother = mother_ids[0] else: labo_ids = labo_obj.search(cr, uid, [("code", "=", row_field(line, "LPFNLB"))]) if labo_ids: mother = dog_obj.create( cr, uid, { "name": row_field(line, "LPFNOM"), "progenus_number": row_field(line, "LPFNPR"), "origin": row_field(line, "LPFNOR"), "tatoo": row_field(line, "LPFTAT"), "sex": "f", "race": row_field(line, "LPRACE"), "birthdate": row_field_date(line, "LPFDTN"), "ship": row_field(line, "LPFPUC"), "pedigree": row_field(line, "LPFNUM"), "labo_id": labo_ids[0], }, ) else: new_labo_f = 0 if row_field(line, "LPFLLB") and row_field(line, "LPFNLB"): new_labo_f = labo_obj.create( cr, uid, { "name": row_field(line, "LPFLLB"), "ref": row_field(line, "LPFRLB"), "code": row_field(line, "LPFNLB"), }, ) mother = dog_obj.create( cr, uid, { "name": row_field(line, "LPFNOM"), "progenus_number": row_field(line, "LPFNPR"), "origin": row_field(line, "LPFNOR"), "tatoo": row_field(line, "LPFTAT"), "sex": "f", "race": row_field(line, "LPRACE"), "birthdate": row_field_date(line, "LPFDTN"), "ship": row_field(line, "LPFPUC"), "pedigree": row_field(line, "LPFNUM"), "labo_id": new_labo_f, }, ) fields["dog_mother"] = mother """ Set the Father dog to labo sample 'LPMNOM':'dog_father/name', 'LPMNUM':'dog_father/pedigree', 'LPMTAT':'dog_father/tatoo', 'LPMPUC':'dog_father/ship', 'LPMNOR':'dog_father/origin', 'LPMDTN':'dog_father/birthdate', 'LPMRLB':'dog_father/labo_id/ref', 'LPMLLB':'dog_father/labo_id/name', 'LPMNLB':'dog_father/labo_id/code', 'LPMNPR':'dog_father/progenus_number', """ fathername = row_field(line, "LPMNOM") if fathername: father = 0 father_ids = dog_obj.search(cr, uid, [("name", "like", fathername)]) if father_ids: father = father_ids[0] else: labo_ids = labo_obj.search(cr, uid, [("code", "=", row_field(line, "LPMNLB"))]) if labo_ids: father = dog_obj.create( cr, uid, { "name": row_field(line, "LPMNOM"), "progenus_number": row_field(line, "LPMNPR"), "origin": row_field(line, "LPMNOR"), "tatoo": row_field(line, "LPMTAT"), "sex": "M", "race": row_field(line, "LPRACE"), "birthdate": row_field_date(line, "LPMDTN"), "ship": row_field(line, "LPMPUC"), "pedigree": row_field(line, "LPMNUM"), "labo_id": labo_ids[0], }, ) else: new_labo_m = 0 if row_field(line, "LPMLLB") and row_field(line, "LPMNLB"): new_labo_m = labo_obj.create( cr, uid, { "name": row_field(line, "LPMLLB"), "ref": row_field(line, "LPMRLB"), "code": row_field(line, "LPMNLB"), }, ) father = dog_obj.create( cr, uid, { "name": row_field(line, "LPMNOM"), "progenus_number": row_field(line, "LPMNPR"), "origin": row_field(line, "LPMNOR"), "tatoo": row_field(line, "LPMTAT"), "sex": "M", "race": row_field(line, "LPRACE"), "birthdate": row_field_date(line, "LPMDTN"), "ship": row_field(line, "LPMPUC"), "pedigree": row_field(line, "LPMNUM"), "labo_id": new_labo_m, }, ) fields["dog_father"] = father """ Set the Child dog to labo sample 'LPCSEX':'dog_child/sex', 'LPCTAT':'dog_child/tatoo', 'LPCPUC':'dog_child/ship', 'LPCDTN':'dog_child/birthdate', 'LPCNPR':'dog_child/progenus_number', 'LPRACE':'dog_child/race', 'LPSEQ':'dog_child/seq', """ child_prog_number = row_field(line, "LPCNPR") if child_prog_number: child = 0 child_ids = dog_obj.search(cr, uid, [("progenus_number", "like", child_prog_number)]) if child_ids: child = child_ids[0] else: labo_ids = labo_obj.search(cr, uid, [("code", "=", 1)]) if labo_ids: child = dog_obj.create( cr, uid, { "name": row_field(line, "LPCNPR"), "progenus_number": row_field(line, "LPCNPR"), #'origin':row_field(line,'LPMNOR'), "tatoo": row_field(line, "LPCTAT"), "sex": row_field(line, "LPCSEX"), "race": row_field(line, "LPRACE"), "birthdate": row_field_date(line, "LPCDTN"), "ship": row_field(line, "LPCPUC"), "seq": row_field(line, "LPSEQ"), "labo_id": labo_ids[0], "parent_m_id": mother, "parent_f_id": father, }, ) else: new_labo_c = labo_obj.create(cr, uid, {"name": "Progenus", "ref": "1", "code": "1"}) child = dog_obj.create( cr, uid, { "name": row_field(line, "LPCNPR"), "progenus_number": row_field(line, "LPCNPR"), #'origin':row_field(line,'LPMNOR'), "tatoo": row_field(line, "LPCTAT"), "sex": row_field(line, "LPCSEX"), "race": row_field(line, "LPRACE"), "birthdate": row_field_date(line, "LPCDTN"), "ship": row_field(line, "LPCPUC"), "seq": row_field(line, "LPSEQ"), "labo_id": new_labo_c, "parent_m_id": mother, "parent_f_id": father, }, ) fields["dog_child"] = child type_id = ( pooler.get_pool(cr.dbname).get("labo.analysis.type").search(cr, uid, [("code", "ilike", "EMPDOG")]) ) type_id_s = type_id and type_id[0] if row_field(line, "LPNRAP") and flag != row_field(line, "LPNRAP"): res = row_field(line, "LPNRAP").split("/") num = ",".join([str(x) for x in res[1:] if x]).replace('"', "").replace(",", "") request_id = req_obj.create(cr, uid, {"type_id": type_id_s, "name": num}) flag = row_field(line, "LPNRAP") else: has_id = req_obj.search(cr, uid, [("type_id", "=", type_id_s)]) request_id = has_id and has_id[0] if not len(has_id): request_id = ( pooler.get_pool(cr.dbname) .get("labo.analysis.request") .create(cr, uid, {"type_id": type_id_s, "name": "to_set"}) ) fields["sample_id"] = request_id sample_id = sample_obj.create(cr, uid, fields) return {}
def _convert_simple_file(self, cr, uid, data, context): sheetnames = [] content=base64.decodestring(data['form']['attach']) xl = tools.readexcel(file_contents = content) shname = xl.worksheets() # header= ["LPNRAP","LPSERV","LPDOSS","LPSEQ","LPENUM","LPENOM","LPENO2","LPEADR","LPELOC","LPRACE","LPFNOM","LPFNUM","LPFTAT","LPFPUC","LPFNOR","LPFDTN","LPFRLB","LPFLLB","LPFNLB","LPFNPR","LPMNOM","LPMNUM","LPMTAT","LPMPUC","LPMNOR","LPMDTN","LPMRLB","LPMLLB","LPMNLB","LPMNPR",'LPCNOM',"LPCSEX","LPCTAT","LPCPUC","LPCDTN","LPCNPR","LPCFIL","LPFILE","LPDTRC","LPNOMT"] fields ={} header=["Dossier","Numpro","date recpt","num1","num2","num3","nom","race","sexe","matiere","dtn","divers1","divers2","preleveur"] partner_obj=pooler.get_pool(cr.dbname).get('res.partner') req_obj=pooler.get_pool(cr.dbname).get('labo.analysis.request') sample_obj=pooler.get_pool(cr.dbname).get('labo.sample') contact_obj=pooler.get_pool(cr.dbname).get('res.partner.address') type_obj=pooler.get_pool(cr.dbname).get('labo.analysis.type') view_b=sample_obj.browse(cr,uid,data['ids'])[0] view_type=view_b.sample_id.type_id.code # view_type=view_type.upper() num='' pp='' flag='' for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) for lines in sheetnames: for line in lines: if line['Numpro']: fields['progenus_number']=line['Numpro'] if line['date recpt']: fields['date_reception']=makeDate(line['date recpt']) or '' fields['identifier_1']=line['num1'] or None fields['identifier_2']=line['num2'] or None fields['identifier_3']=line['num3'] or None fields['name_animal']=line['nom'] or None fields['breed']=line['race'] or None fields['sex']=line['sexe'] or None fields['material']=line['matiere'] or None fields['birthdate']=makeDate(line['dtn']) or None fields['misc_1']=line['divers1'] or None fields['misc_2']=line['divers2'] or None if line['preleveur']: prelev_id=partner_obj.search(cr, uid, [('name', '=', line['preleveur'])]) if len(prelev_id): fields['preleveur_id']=prelev_id[0] else: # ADD Eleveur AS A PARTNER new_tatooer=partner_obj.create(cr,uid,{'name': line['preleveur']}) fields['preleveur_id']=new_tatooer if len(line['Dossier']):# and flag!=line['Dossier']: # if '/' in line['Dossier']: res=line['Dossier'].split('/') if len(res)>2: num=res[1]+'/'+res[2] type_name=res and res[0] or None type_name=type_name.upper() else: type_name=view_type.upper() type_id_s=type_obj.search(cr,uid,[('code','ilike',type_name)]) # CHECK IF REQUEST ALREADY EXITS if num: r_id=req_obj.search(cr,uid,[('name','=',num),('type_id','=', type_id_s[0])]) if len(r_id): request_id=r_id[0] else: request_id=req_obj.create(cr,uid,{'type_id':type_id_s[0], 'name':num}) flag=line['Dossier'] elif line['Dossier'] and flag==line['Dossier']: request_id=request_id else: has_id=req_obj.search(cr,uid,[('type_id','=',type_id_s[0]),('name','=','0000/0000')]) request_id=has_id and has_id[0] if not has_id and pp!='y': request_id=pooler.get_pool(cr.dbname).get('labo.analysis.request').create(cr,uid,{'type_id':type_id_s[0], 'name':'0000/0000'}) pp='y' flag_is='yes' else: request_id=request_id fields['sample_id']=request_id sample_id=sample_obj.create(cr,uid,fields) return {} return {}
def _convert_attach_xsl(self, cr, uid, data, context): content=base64.decodestring(data['form']['attach']) list= content.split('\n')[1:] labo_obj=pooler.get_pool(cr.dbname).get('labo.labo') doss_obj=pooler.get_pool(cr.dbname).get('doss.dog') req_obj=pooler.get_pool(cr.dbname).get('labo.analysis.request') sample_obj=pooler.get_pool(cr.dbname).get('labo.sample') dog_obj=pooler.get_pool(cr.dbname).get('labo.dog') partner_obj=pooler.get_pool(cr.dbname).get('res.partner') contact_obj=pooler.get_pool(cr.dbname).get('res.partner.address') type_obj=pooler.get_pool(cr.dbname).get('labo.analysis.type') seq_obj=pooler.get_pool(cr.dbname).get('ir.sequence') type_id=type_obj.search(cr, uid,[('code', 'ilike', 'EMPDOG')]) type_id_s=type_id and type_id[0] type_id2=type_obj.search(cr, uid,[('code', 'ilike', 'EMPDOG_2')]) type_id_s2=type_id2 and type_id2[0] type_id3=type_obj.search(cr, uid,[('code', 'ilike', 'EMPCHE')]) type_id_s3=type_id3 and type_id3[0] view_type='' view_b=sample_obj.browse(cr,uid,data['ids'])[0] view_type=view_b.sample_id.type_id.code flag='' flag2='' flag_f='' flag_m='' pp='' type_a='' sheetnames = [] nbr = 0 flag1='' global sampleids sampleids = [] header= ["LPNRAP","LPSERV","LPDOSS","LPSEQ","LPENUM","LPENOM","LPENO2","LPEADR","LPELOC","LPRACE","LPFNOM","LPFNUM","LPFTAT","LPFPUC","LPFNOR","LPFDTN","LPFRLB","LPFLLB","LPFNLB","LPFNPR","LPMNOM","LPMNUM","LPMTAT","LPMPUC","LPMNOR","LPMDTN","LPMRLB","LPMLLB","LPMNLB","LPMNPR",'LPCNOM',"LPCSEX","LPCTAT","LPCPUC","LPCDTN","LPCNPR","LPCFIL","LPFILE","LPDTRC","LPNOMT"] fields ={} fields_prelev=['name','code'] flag_is='' xl = tools.readexcel(file_contents = content) shname = xl.worksheets() num_prog='' global flag_v flag_v='n' for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) i=0 for lines in sheetnames: for line in lines: try: fields={} flag_v='n' if not len(line): continue view_b=sample_obj.browse(cr,uid,data['ids'])[0] view_type=view_b.sample_id.type_id.code # Try to find prelev s information if line['LPNRAP']: res=line['LPNRAP'].split('/') if len(res)>2: view_type=res[0] type_id=type_obj.search(cr, uid,[('code', 'ilike', view_type)]) type_id_s=type_id and type_id[0] if view_type.upper() not in ('EMPCHE', 'EMPDOG', 'EMPDOG_2'): raise wizard.except_wizard('Error!', 'You are trying to import from a non-complex analysis.\n Try to change the request name %s\n and set its type to EMPCHE, EMPDOG or EMPDOG_2 '%line['LPNRAP']) if view_type.upper()=="EMPDOG": type_id_s=type_id_s type_a='dog' elif view_type.upper()=="EMPDOG_2": type_id_s=type_id_s2 type_a='dog' elif view_type.upper()=="EMPCHE": type_id_s=type_id_s3 type_a='horse' else: type_a=None view_type=view_type and view_type.upper() # raise wizard.except_wizard('Error!', 'You are trying to import from a non-complex analysis \n Try to set a request name to "%s" \n Or import trough the menu EMPCHE, EMPDOG or EMPDOG_2 '%line['LPFNOR']) if line['LPSERV']: fields['lp_serv']=line['LPSERV'] try: if line['LPNOTE']: fields['notice']=line['LPNOTE'] except: raise wizard.except_wizard('Error!', 'The column LPNOTE is not your file! \n Please check the structure of your file') if line['LPDTRC']:# and len(['LPDTRC'])>3:# and len(line['LPDTRC'])>2: # pri nt "dte", line['LPDTRC'] fields['date_reception']=_makeDate(line['LPDTRC']) #or '' fields['lp_file']=line['LPFILE'] try: if line['LPNOMT']: tatoo_id=partner_obj.search(cr, uid, [('name', 'like', line['LPNOMT'])]) if len(tatoo_id): fields['tatooer_id']=tatoo_id[0] or None else: # ADD Tatooer AS A PARTNER new_tatooer=partner_obj.create(cr,uid,{'name': line['LPNOMT']}) fields['tatooer_id']=new_tatooer or None except Exception, e: raise wizard.except_wizard('Error!', 'The column LPNOMT is not your file! \n Please check the structure of your file: (%s)'%(e,)) continue if line['LPENOM']: prelev_id=partner_obj.search(cr, uid, [('name', '=', line['LPENOM'] + ' ' + (line['LPENO2'] or '') )]) if len(prelev_id): fields['preleveur1_id']=prelev_id[0] or None elif not line['LPENOM']: fields['preleveur1_id']=None else: # ADD PRELEVER AS A PARTNER AND "COORDINATES" new_prelev=partner_obj.create(cr,uid,{'name': line['LPENOM'] +' '+ (line['LPENO2']), 'ref':line['LPENUM'], }) city_zip=line['LPELOC'].split(' ') zip='' zip=city_zip[0] city=len(city_zip)==2 and city_zip[1] and city_zip[1:] or '' new_contact_prelev=contact_obj.create(cr,uid,{'name': line['LPENOM'] + ' '+ (line['LPENO2'] or ''), 'city':city and city[0].replace('"',''), 'street':line['LPEADR'], 'zip':zip and zip.replace('"',''), 'partner_id':new_prelev }) fields['preleveur1_id']=new_prelev or None # CREATE FEMALE DOG # SEARCH AND CREATE LABO INFORMATION IF NOT EXISTING labo_femal_id='' dogfemal_id='' if line['LPFNPR'] and str(line['LPFNPR'])!='0': num_prog=line['LPFNPR'] code_femal=line['LPFNLB'] if str(line['LPFNLB'])=='0': code_femal='1' labofemal_id=labo_obj.search(cr,uid,[('code','=',code_femal)]) if len(labofemal_id): labo_femal_id=labofemal_id[0] elif line['LPFNLB'] and int(line['LPFNLB'])>0: new_labo_f=labo_obj.create(cr,uid,{ 'name':line['LPFLLB'], # 'ref':line['LPFRLB'], 'code':line['LPFNLB'], }) labo_femal_id=new_labo_f # Use progenus number or origin number to find femal dog flag2='' ##CHECK CONDITION TO SET if line['LPFNPR'] and str(line['LPFNPR'])!='0': num_prog=line['LPFNPR'] dogfemal_id='' flag2='' if (view_type=="EMPCHE" or view_type=="EMPDOG" or view_type=="EMPDOG_2") and flag2!='y': num_prog=line['LPFNPR'] if line['LPFNOM'] and str(line['LPFNOM'].encode('utf-8'))!='0' and (not dogfemal_id or dogfemal_id==None) and view_type=="EMPCHE": dogfemal_id=dog_obj.search(cr,uid,[('name','=',line['LPFNOM'].encode('utf-8'))]) dogfemal_id.sort(reverse=True) dogfemal_id=dogfemal_id and dogfemal_id[0] flag2='y' if line['LPFNPR'] and (not dogfemal_id or dogfemal_id==None): dogfemal_id=dog_obj.search(cr,uid,[('progenus_number','=',line['LPFNPR'])]) dogfemal_id.sort(reverse=True) dogfemal_id=dogfemal_id and dogfemal_id[0] if line['LPFNOR'] and (not dogfemal_id or dogfemal_id==None): dogfemal_id=dog_obj.search(cr,uid,[('origin','=',line['LPFNOR'])]) dogfemal_id.sort(reverse=True) dogfemal_id=dogfemal_id and dogfemal_id[0] if dogfemal_id: num_tmp=dog_obj.browse(cr,uid,dogfemal_id).progenus_number if not num_tmp and line['LPFNPR'] and line['LPFNPR'] and str(line['LPFNPR'])!='0': dog_obj.write(cr,uid,[dogfemal_id],{'progenus_number':line['LPFNPR']}) if num_tmp and line['LPFNPR'] and str(line['LPFNPR'])!='0' and num_tmp!=str(line['LPFNPR']): dogfemal_id='' if (not(dogfemal_id) or dogfemal_id==None) and line['LPFNOM'].encode('utf8') and line['LPFNOM'].encode('utf-8')!='0':# or not line['LPMNPR']: dogfemal_id=dog_obj.create(cr,uid,{'name':line['LPFNOM'].encode('utf-8'), 'progenus_number':num_prog or None, 'origin':line['LPFNOR'], 'tatoo':line['LPFTAT'], 'sex':'F', 'ref_dog':line['LPFRLB'], 'race':line['LPRACE'], 'birthdate':_makeDate(line['LPFDTN']), 'ship':line['LPFPUC'], 'pedigree':line['LPFNUM'] or None, 'type_animal':type_a, }) if labo_femal_id: if dogfemal_id and dogfemal_id!=None: dog_obj.write(cr,uid,[dogfemal_id],{'labo_id':labo_femal_id}) if dogfemal_id and dogfemal_id!=None: # if view_type=="EMPDOG_2": # flag_v='YES' fields['dog_mother']=dogfemal_id or None if str(line['LPFNLB'])=='1': dog_obj.write(cr,uid, [dogfemal_id], {'done_i':True}) doss_obj.create(cr,uid,{'name': line['LPDOSS'], 'dog_id1':dogfemal_id}) # else: # fields['dog_mother']= None #don t need this part # if line['LPFNOM'] and view_type!='EMPCHE' and view_type!="EMPDOG" and view_type!="EMPDOG_2": # if line['LPFNPR'] and str(line['LPFNPR']!='0'): # dogfemal_id=dog_obj.search(cr,uid,[('progenus_number','=',line['LPFNPR'])]) # dogfemal_id=dogfemal_id and dogfemal_id[0] # flag2='y' # if line['LPMNOR'] and (not dogfemal_id or dogfemal_id==None): # dogfemal_id=dog_obj.search(cr,uid,[('origin','=',line['LPFNOR'])]) # dogfemal_id=dogfemal_id and dogfemal_id[0] # # # flag2='y' # # if not line['LPFNPR'] and str(line['LPFNPR'])!='0' or flag2=='y': # # dogfemal_id=dog_obj.search(cr,uid,[('origin','=',line['LPFNOR'])]) # # dogfemal_id=dogfemal_id and dogfemal_id[0] # # if (not(dogfemal_id) or dogfemal_id==None) and line['LPFNOM']:# or not line['LPFNPR'] or line['LPFNPR']=='0': # dogfemal_id=dog_obj.create(cr,uid,{'name':line['LPFNOM'], # 'progenus_number':num_prog, # 'origin':line['LPFNOR'], # 'tatoo':line['LPFTAT'], # 'sex':'F', # 'race':line['LPRACE'], # 'birthdate':_makeDate(line['LPFDTN']) or None, # 'ship':line['LPFPUC'], # 'pedigree':line['LPFNUM'], # 'type_animal':type_a, # # 'labo_id':labo_m_id # }) # if labo_femal_id: # dog_obj.write(cr,uid,[dogfemal_id],{'labo_id':labo_femal_id}) # # # fields['dog_mother']=dogfemal_id #end unusef ul code # CREATE MALE DOG # SEARCH AND CREATE LABO INFORMATION IF NOT exist code_mal=line['LPMNLB'] if str(line['LPMNLB'])=='0': code_mal='1' labomal_id=labo_obj.search(cr,uid,[('code','=',code_mal)]) labo_mal_id='' dogmal_id='' num_prog=line['LPMNPR'] if len(labomal_id): labo_mal_id=labomal_id[0] elif line['LPMLLB'] and line['LPMNLB'] and int(line['LPMNLB'])>0: new_labo_d=labo_obj.create(cr,uid,{ 'name':line['LPMLLB'], # 'ref':line['LPMRLB'], 'code':line['LPMNLB'], }) # Use progenus number or origin number to find mal dog labo_mal_id=new_labo_d flag3='' if line['LPMNPR'] and str(line['LPMNPR'])!='0': num_prog=line['LPMNPR'] dogmal_id='' # if view_type=="EMPDOG_2" and flag_v=='YES': # fields['dog_father']=None if (view_type=="EMPCHE" or view_type=="EMPDOG" or view_type=="EMPDOG_2") and flag3!='y': # if view_type=="EMPCHE" and flag3!='y': num_prog=line['LPMNPR'] if (line['LPMNOM'] and str(line['LPMNOM'].encode('utf-8'))!='0') and (not dogmal_id or dogmal_id==None) and view_type=="EMPCHE": dogmal_id=dog_obj.search(cr,uid,[('name','=',line['LPMNOM'].encode('utf)8'))]) dogmal_id.sort(reverse=True) dogmal_id=dogmal_id and dogmal_id[0] flag3='y' if line['LPMNPR'] and (not dogmal_id or dogmal_id==None): dogmal_id=dog_obj.search(cr,uid,[('progenus_number','=',line['LPMNPR'])]) dogmal_id.sort(reverse=True) dogmal_id=dogmal_id and dogmal_id[0] if line['LPMNOR'] and (not dogmal_id or dogmal_id==None): dogmal_id=dog_obj.search(cr,uid,[('origin','=',line['LPMNOR'])]) dogmal_id.sort(reverse=True) dogmal_id=dogmal_id and dogmal_id[0] if dogmal_id: num_tmp=dog_obj.browse(cr,uid,dogmal_id).progenus_number if not num_tmp and line['LPMNPR'] and str(line['LPMNPR'])!='0': dog_obj.write(cr,uid,[dogmal_id],{'progenus_number':line['LPMNPR']}) if num_tmp and line['LPMNPR'] and str(line['LPMNPR'])!='0' and num_tmp!=str(line['LPMNPR']): dogmal_id='' # if dogmal_id: if (not(dogmal_id) or dogmal_id==None) and line['LPMNOM'].encode('utf)8') and line['LPMNOM']!='0':# or not line['LPMNPR']: dogmal_id=dog_obj.create(cr,uid,{'name':line['LPMNOM'].encode('utf-8'), 'progenus_number':num_prog, 'origin':line['LPMNOR'], 'tatoo':line['LPMTAT'], 'sex':'M', 'race':line['LPRACE'], 'ref_dog':line['LPMRLB'], 'birthdate':_makeDate(line['LPMDTN']), 'ship':line['LPMPUC'], 'pedigree':line['LPMNUM'] or None, 'type_animal':type_a, }) if labo_mal_id and labo_mal_id!=None and dogmal_id: dog_obj.write(cr,uid,[dogmal_id],{'labo_id':labo_mal_id or None}) if dogmal_id and dogmal_id!=None and len(str(dogmal_id)): # if flag_v!='YES':# and view_type=="EMPDOG_2": fields['dog_father']=dogmal_id or None if str(line['LPMNLB'])=='1': dog_obj.write(cr,uid, [dogmal_id], {'done_i':True}) doss_obj.create(cr,uid,{'name': line['LPDOSS'], 'dog_id1':dogmal_id } ) # else: # fields['dog_father']=None # if line['LPMNOM'] and view_type!='EMPCHE': # if line['LPMNPR'] and str(line['LPMNPR'])!='0': # dogmal_id=dog_obj.search(cr,uid,[('progenus_number','=',line['LPMNPR'])]) # dogmal_id=dogmal_id and dogmal_id[0] # flag3='y' # if not line['LPMNPR'] or flag3=='y': # dogmal_id=dog_obj.search(cr,uid,[('origin','=',line['LPMNOR'])]) # dogmal_id=dogmal_id and dogmal_id[0] # if not(dogmal_id) and line['LPMNOM']:# or not line['LPMNPR']: # dogmal_id=dog_obj.create(cr,uid,{'name':line['LPMNOM'], # 'progenus_number':num_prog, # 'origin':line['LPMNOR'], # 'tatoo':line['LPMTAT'], # 'sex':'M', # 'race':line['LPRACE'], # 'birthdate':_makeDate(line['LPMDTN']), # 'ship':line['LPMPUC'], # 'pedigree':line['LPMNUM'] or None, # 'type_animal':type_a, # }) # if labo_mal_id: # dog_obj.write(cr,uid,[dogmal_id],{'labo_id':labo_mal_id}) # fields['dog_father']=dogmal_id if line['LPDOSS']: fields['lp_doss']=line['LPDOSS'] if line['LPCFIL']: fields['res_filiation']=line['LPCFIL'] # CREATE PUPPY # SEARCH AND CREATE PROGENUS LABO INFORMATION labop_id=labo_obj.search(cr,uid,[('code','=',1)]) if len(labop_id): labo_p_id=labop_id[0] else: new_labo_p=labo_obj.create(cr,uid,{ 'name':'Progenus', 'ref':'1', 'code':'1', }) labo_p_id=new_labo_p # SEARCH PUPPY puppy_id='' if view_type=="EMPCHE": try: name=line['LPCNOM'].encode('utf-8') except: raise wizard.except_wizard('Error!', 'The column LPCNOM is not your file! \n Please check the structure of your file') if line['LPCNOM'] and str(line['LPCNOM'].encode('utf-8'))!='0' and (not puppy_id or puppy_id==None): puppy_id=dog_obj.search(cr,uid,[('name','=',line['LPCNOM'].encode('utf-8'))]) puppy_id=puppy_id and puppy_id[0] flag2='y' if line['LPCNPR'] and str(line['LPCNPR'])!='0': puppy_id=dog_obj.search(cr, uid, [('progenus_number','=', line['LPCNPR'])]) puppy_id=puppy_id and puppy_id[0] # compare using sequence and DOSS if not puppy_id or puppy_id==None: m_id=dog_obj.search(cr,uid,[('name','=',line['LPMNOM'].encode('utf-8'))]) f_id=dog_obj.search(cr,uid,[('name','=',line['LPFNOM'].encode('utf-8'))]) a=m_id and m_id[0] b=f_id and f_id[0] if not len(f_id): f_id=dog_obj.search(cr,uid,[('tatoo','=',line['LPFTAT'])]) else: f_id=dog_obj.search(cr,uid,[('origin','=',line['LPFNOR'])]) b=f_id and f_id[0] if not len(m_id): m_id=dog_obj.search(cr,uid,[('tatoo','=',line['LPMTAT'])]) else: m_id=dog_obj.search(cr,uid,[('origin','=',line['LPMNOR'])]) a=m_id and m_id[0] if a and a!=None and b and b!=None: cr.execute("SELECT id from labo_dog where parent_f_id=%d and parent_m_id=%d"%(a,b)) res=cr.fetchone() puppy_id=res and res[0] else: num_prog=line['LPCNPR'] flag1='y' if not puppy_id or puppy_id==None: # find mum of child m_id=dog_obj.search(cr,uid,[('name','=',line['LPMNOM'].encode('utf-8'))]) f_id=dog_obj.search(cr,uid,[('name','=',line['LPFNOM'].encode('utf-8'))]) a=m_id and m_id[0] b=f_id and f_id[0] if a and a!=None and b and b!=None: cr.execute("SELECT id from labo_dog where parent_f_id=%d and parent_m_id=%d"%(a,b)) res=cr.fetchone() puppy_id=res and res[0] try: name=line['LPCNOM'].encode('utf-8') except: raise wizard.except_wizard('Error!', 'The column LPCNOM is not your file! \n Please check the structure of your file') if puppy_id and line['LPCNPR'] and str(line['LPCNPR'])!='0': num_p=dog_obj.browse(cr,uid,puppy_id).progenus_number if not num_p and line['LPCNPR']: dog_obj.write(cr,uid,[puppy_id],{'progenus_number':line['LPCNPR']}) if num_p and line['LPCNPR'] and num_p!=str(line['LPCNPR']): puppy_id='' if not puppy_id or puppy_id==None: puppy_id=dog_obj.create(cr,uid,{ 'name':line['LPCNOM'].encode('utf-8'), 'progenus_number':str(line['LPCNPR'])!='0' and line['LPCNPR'], # 'seq':line['LPSEQ'], 'tatoo':line['LPCTAT'], 'sex':line['LPCSEX'], 'race':line['LPRACE'], 'birthdate':_makeDate(line['LPCDTN']), 'ship':line['LPCPUC'], 'parent_m_id':dogfemal_id or None, 'parent_f_id':dogmal_id or None, 'labo_id':labo_p_id or None, 'type_animal':type_a, }) if puppy_id and puppy_id!=None: fields['dog_child']=puppy_id #dog_obj.write(cr,uid, [puppy_id], {'done_i':True}) doss_obj.create(cr,uid,{'name': line['LPDOSS'] or None, 'dog_id1':puppy_id}) if line['LPSEQ']: fields['seq_horse']=line['LPSEQ'] puppy_id='' if view_type=="EMPDOG": # ##1 # if line['LPCNOM'] and str(line['LPCNOM'].encode('utf-8'))!='0' and (not puppy_id or puppy_id==None): # puppy_id=dog_obj.search(cr,uid,[('name','=',line['LPCNOM'].encode('utf-8'))]) # puppy_id=puppy_id and puppy_id[0] or None # #END of 1 if line['LPCNPR'] and str(line['LPCNPR'])!='0' and (not puppy_id or puppy_id==None): puppy_id=dog_obj.search(cr, uid, [('progenus_number','=', line['LPCNPR'])]) puppy_id=puppy_id and puppy_id[0] # compare using sequence and DOSS if not puppy_id: m_id=dog_obj.search(cr,uid,[('origin','=',line['LPMNOR'])]) f_id=dog_obj.search(cr,uid,[('origin','=',line['LPFNOR'])]) a=m_id and m_id[0] b=f_id and f_id[0] c=int(line['LPSEQ']) cr.execute("SELECT id from labo_dog where seq=%d and parent_f_id=%d and parent_m_id=%d"%(c,a,b)) res=cr.fetchone() puppy_id=res and res[0] else: num_prog=line['LPCNPR'] flag1='y' if not(line['LPCNPR']) or str(line['LPCNPR'])=='0' and ( not(puppy_id) or puppy_id==None): # find mum of child m_id=dog_obj.search(cr,uid,[('origin','=',line['LPMNOR'])]) f_id=dog_obj.search(cr,uid,[('origin','=',line['LPFNOR'])]) a=m_id and m_id[0] b=f_id and f_id[0] c=line['LPSEQ'] and int(line['LPSEQ']) if a and a!=None and b and b!=None and c and c!=None: cr.execute("SELECT id from labo_dog where seq=%d and parent_f_id=%d and parent_m_id=%d"%(c,b,a)) res=cr.fetchone() puppy_id=res and res[0] if puppy_id and line['LPCNPR'] and str(line['LPCNPR'])!='0': num_p=dog_obj.browse(cr,uid,puppy_id).progenus_number if not num_p and line['LPCNPR']: dog_obj.write(cr,uid,[puppy_id],{'progenus_number':line['LPCNPR']}) if num_p and num_p!=str(line['LPCNPR']): puppy_id='' if (line['LPCNPR']) and str(line['LPCNPR'])=='0' and puppy_id==None or not puppy_id: # num_prog=line['LPCNPR'] # if not puppy_id or puppy_id==None: puppy_id=dog_obj.create(cr,uid,{ # 'name':line['LPCNOM'], 'progenus_number':line['LPCNPR'], 'seq':line['LPSEQ'], 'tatoo':line['LPCTAT'], 'sex':line['LPCSEX'], 'race':line['LPRACE'], 'birthdate':_makeDate(line['LPCDTN']), 'ship':line['LPCPUC'], 'parent_m_id':dogfemal_id or None, 'parent_f_id':dogmal_id or None, 'labo_id':labo_p_id, 'type_animal':type_a, }) if puppy_id and puppy_id!=None: fields['dog_child']=puppy_id # dog_obj.write(cr,uid, [puppy_id], {'done_i':True}) doss_obj.create(cr,uid,{'name': line['LPDOSS'] or None, 'dog_id1':puppy_id}) flag1='' # SET A REQUEST # REQUEST FILLED IN THE ATTACHMENT if line['LPNRAP']:# and flag!=line['LPNRAP']: res=line['LPNRAP'].split('/') if len(res)>2: num=res[1]+'/'+res[2] # CHECK IF REQUEST ALREADY EXITS if res[0]: view_type=res[0] type_id=type_obj.search(cr, uid,[('code', 'ilike', view_type)]) type_id_s=type_id and type_id[0] elif view_type=="EMPDOG": type_id_s=type_id_s elif view_type=="EMPDOG_2": type_id_s=type_id_s2 elif view_type=="EMPCHE": type_id_s=type_id_s3 r_id=req_obj.search(cr,uid,[('name','=',num),('type_id','=',type_id_s)]) if len(r_id): request_id=r_id[0] else: request_id=req_obj.create(cr,uid,{'type_id':type_id_s, 'name':num}) flag=line['LPNRAP'] elif line['LPNRAP'] and flag==line['LPNRAP']: request_id=request_id else: has_id=req_obj.search(cr,uid,[('type_id','=',type_id_s),('name','=','0000/0000')]) request_id=has_id and has_id[0] if not has_id and pp!='y': request_id=pooler.get_pool(cr.dbname).get('labo.analysis.request').create(cr,uid,{'type_id':type_id_s, 'name':'0000/0000'}) pp='y' flag_is='yes' else: request_id=request_id fields['sample_id']=request_id or None sample_id=sample_obj.create(cr,uid,fields) sampleids.append(sample_id) except Exception, e: raise wizard.except_wizard('Error!', '%s \n The problem is coming from this line! Please check its content \n \n %s' %(e,line.values(),))
def _convert_attach_xsl(self,cr,uid,data,context=None): fields ={} content=base64.decodestring(data['form']['attach']) list= content.split('\n')[1:] labo_obj=pooler.get_pool(cr.dbname).get('labo.labo') req_obj=pooler.get_pool(cr.dbname).get('labo.analysis.request') type_obj=pooler.get_pool(cr.dbname).get('labo.analysis.type') sample_obj=pooler.get_pool(cr.dbname).get('labo.sample') dog_obj=pooler.get_pool(cr.dbname).get('labo.dog') seq_obj = pooler.get_pool(cr.dbname).get('ir.sequence') dict_s={} dict_s2={} max_v='' j=0 type_id=type_obj.search(cr,uid,[('code','ilike','EMPDOG')]) sheetnames=[] xl=tools.readexcel(file_contents = content) shname = xl.worksheets() for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) for lines in sheetnames: for line in lines: dict_s[line['LPDOSS'],line['LPSEQ']]=(line['LPNRAP'],line['LPFNPR'],line['LPMNPR'],line['LPCSEX'],line['LPCTAT'],line['LPCPUC'],line['LPCNPR'],line['LPCFIL'],line['LPDTRC']) v_tmp=line['LPNRAP'].split('/') if len(v_tmp)>2: v_name=v_tmp[1] +'/'+ v_tmp[2] dict_s2[line['LPDOSS']]=(v_name) infos_dict=dict_s.keys() flag='' flag_is='' flag1='' list_doss=[] a=[] flag_quit='' flag_r='' flag_ss='' dict_p={} i=0 k=sample_obj.browse(cr,uid,data['ids']) cr.execute("SELECT number_next,code from ir_sequence where prefix like 'cc'") res_cr1=cr.fetchone() cr.execute("SELECT number_next,code from ir_sequence where prefix like 'che'") res_cr2=cr.fetchone() while i < len(dict_s.keys()): infos_dict=dict_s.keys()[i] # cr.execute("select s.id,s.dog_child,s.dog_mother,s.dog_father,r.id from labo_dog d, labo_analysis_request r, labo_sample s where s.sample_id=r.id and d.id=s.dog_child and d.seq=%d and s.lp_doss=%d"%(int(infos_dict[1]), int(infos_dict[0])) ) cr.execute("select s.id,s.dog_child,s.dog_mother,s.dog_father,r.id from labo_dog d, labo_analysis_request r, labo_sample s where d.seq=%d and s.lp_doss=%d and s.id in %s"%(int(infos_dict[1]), int(infos_dict[0]), "("+",".join(map(str,data['ids']))+")") ) res=cr.fetchone() # UPDATE SAMPLES WITH RESULTS # RECEPTION DATE if res and res[0]: print "res",res[0] sample_obj.write(cr,uid,[res[0]],{'date_reception':_makeDate(dict_s.values()[i][8]) or None, 'res_filiation':(dict_s.values()[i][7]) or None }) # fill fields puppy puppy_id=res and res[1] print "res1",res[1],dict_s.values()[i][3] if puppy_id and puppy_id!=None: dog_obj.write(cr,uid,[puppy_id],{'tatoo':(dict_s.values()[i][4]) or None, 'ship':(dict_s.values()[i][5]) or None, 'sex':(dict_s.values()[i][3]) or None, }) if dict_s.values()[i][6] and str(dict_s.values()[i][6])!='0': prog_num= dict_s.values()[i][6] dog_obj.write(cr,uid,[puppy_id],{'progenus_number':prog_num}) # fill fields mother mother_id=res and res[2] # if mother_id : # if dict_s.values()[i][1] and str(dict_s.values()[i][1])!='0': # prog_num=dict_s.values()[i][1] # prog_num=seq_obj.get(cr,uid,res_cr1[1]) # dog_obj.write(cr,uid,[mother_id],{'progenus_number':prog_num}) # fill fields father father_id=res and res[3] if father_id: if dict_s.values()[i][2] and str(dict_s.values()[i][2])!='0': prog_num=dict_s.values()[i][2] dog_obj.write(cr,uid,[father_id],{'progenus_number':prog_num}) # fill name of request req_id=res and res[4] i+=1 # REQUEST NUMBER FILLED IN ATTACHMENT # use dict_s2 # check if request exists for val in dict_s2.keys(): rek_id='' flag_r='' cr.execute("select id from labo_sample where lp_doss=%d"%(int(val))) ids_s=cr.fetchall() ids_res=ids_s and ids_s[0] for it in ids_s: cr.execute("select r.id from labo_analysis_request r, labo_analysis_type t where t.id=r.type_id and r.name like '%s' and t.code ilike 'EMPDOG'" %(dict_s2[val])) res_r=cr.fetchone() it_id=",".join([str(x) for x in it if x]) if not res_r and flag_r!='y': flag_r='y' rek_id=req_obj.create(cr,uid,{'name': dict_s2[val], 'type_id':type_id and type_id[0]}) elif res_r: res_k=res_r and res_r[0] rek_id=res_k sample_obj.write(cr,uid,[int(it_id)],{'sample_id':rek_id}) return{}
def _import_attach(self, cr, uid, data, context): list_alpha = [ "A01", "B01", "C01", "D01", "E01", "F01", "G01", "H01", "A02", "B02", "C02", "D02", "E02", "F02", "G02", "H02", "A03", "B03", "C03", "D03", "E03", "F03", "G03", "H03", "A04", "B04", "C04", "D04", "E04", "F04", "G04", "H04", "A05", "B05", "C05", "D05", "E05", "F05", "G05", "H05", "A06", "B06", "C06", "D06", "E06", "F06", "G06", "H06", "A07", "B07", "C07", "D07", "E07", "F07", "G07", "H07", "A08", "B08", "C08", "D08", "E08", "F08", "G08", "H08", "A09", "B09", "C09", "D09", "E09", "F09", "G09", "H09", "A10", "B10", "C10", "D10", "E10", "F10", "G10", "H10", "A11", "B11", "C11", "D11", "E11", "F11", "G11", "H11", "A12", "B12", "C12", "D12", "E12", "F12", "G12", "H12", ] c = pooler.get_pool(cr.dbname).get("labo.sample").get_view_context(cr, uid, context) content = base64.decodestring(data["form"]["attach"]) list = content.split("\n")[1:] xl = tools.readexcel(file_contents=content) shname = xl.worksheets() sheetnames = [] # fields ={'progenus_number':False,'num_alpha':False} if shname: sh = shname[0] a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) req_obj = pooler.get_pool(cr.dbname).get("labo.analysis.request") sample_obj = pooler.get_pool(cr.dbname).get("labo.sample") labo_setup_obj = pooler.get_pool(cr.dbname).get("labo.setup") setup_obj = pooler.get_pool(cr.dbname).get("analysis.setup") setup_hist_obj = pooler.get_pool(cr.dbname).get("setup.history") dog_obj = pooler.get_pool(cr.dbname).get("labo.dog") user_obj = pooler.get_pool(cr.dbname).get("res.users") view_b = sample_obj.browse(cr, uid, data["ids"])[0] view_type = view_b.cont if not view_type: view_type = view_b.sample_id.type_id.code flag = "" flag1 = "" a_set_ids = [] user_id = "" for lines in sheetnames: first_lines = lines[:5] last_lines = lines[11:] a = first_lines[0].keys() set_up_n = a[0] != "F1" and a[0] or "" page_number = first_lines[0].values()[0] x1 = first_lines[1].values()[0] date_f = first_lines[2].values()[0] operat = first_lines[3].values()[0] if operat: user_ids = user_obj.search(cr, uid, [("login", "=", operat)]) if user_ids: user_id = user_ids and user_ids[0] or None # continue till the 5th columns set_up_ids = labo_setup_obj.search(cr, uid, [("name", "=", page_number)]) set_up_id = set_up_ids and set_up_ids[0] if not set_up_id: # and flag!=page_number: flag = page_number set_up_id = labo_setup_obj.create(cr, uid, {"name": page_number, "date_s": date_f}) # #search analysis setup # a_set_ids=setup_obj.search(cr,uid,[('set_up','=',set_up_id)]) # a_set_id=a_set_ids and a_set_ids[0] or '' # if not len(a_set_ids):# and flag1!=set_up_id: # a_set_id=setup_obj.create(cr,uid,{'set_up':set_up_id, 'well':c.index(a.values()[1])}) for i in last_lines: prog = str(i.values()[0]) try: t = list_alpha.index(i.values()[1].upper()) except: raise wizard.except_wizard("Error!", "Please, Check the value '%s' in your file" % i.values()[1]) a_set_ids = setup_obj.search( cr, uid, [("set_up", "=", set_up_id), ("well", "=", list_alpha.index(i.values()[1].upper()) + 1)] ) a_set_id = a_set_ids and a_set_ids[0] or "" if not len(a_set_ids): a_set_id = setup_obj.create( cr, uid, {"set_up": set_up_id, "well": list_alpha.index(i.values()[1]) + 1, "run_setup": None} ) if view_type != "EMPDOG" and view_type != "EMPDOG_2" and view_type != "EMPCHE" and prog: cr.execute("select id from labo_sample where progenus_number = '%s'" % (prog)) res2 = cr.fetchall() li = [] for l in res2: li.append(l[0]) for r in li: c = sample_obj.browse(cr, uid, r) # if user_id: # sample_obj.write(cr,uid,c.id,{'user_id':user_id}) # ADD HISTORY if ( c.file_setup and c.file_setup.set_up and c.file_setup.set_up.name and (c.file_setup.set_up.name != str(page_number)) ): r = setup_hist_obj.create( cr, uid, { "name": time.strftime("%Y-%m-%d"), "sample_id": c.id, "old_alpha": c.num_alpha, "setup_id2": c.file_setup.set_up.id or "", "setup_id": a_set_id, # or None }, ) k = sample_obj.write( cr, uid, c.id, {"num_alpha": i.values()[1], "file_setup": a_set_id, "state": "ko"} ) elif view_type in ("EMPDOG", "EMPDOG_2", "EMPCHE") and prog: cr.execute("select d.id from labo_dog d where d.progenus_number = '%s' " % (prog)) # cr.execute("select l.id from labo_dog d,labo_sample l,labo_plate p where d.progenus_number = '%s' and (l.dog_child=d.id or l.dog_father=d.id or l.dog_mother=d.id)"%(prog)) res1 = cr.fetchall() li = [] for l in res1: li.append(l[0]) for r in li: c = dog_obj.browse(cr, uid, r) # if user_id: # dog_obj.write(cr,uid,c.id,{'user_id':user_id}) # ADD HISTORY if ( c.file_setup and c.file_setup.set_up and c.file_setup.set_up.name and (c.file_setup.set_up.name != str(page_number)) ): z = setup_hist_obj.create( cr, uid, { "name": time.strftime("%Y-%m-%d"), "dog_id1": c.id, "setup_id2": c.file_setup.set_up.id or "", "old_alpha": c.num_alpha, "setup_id": a_set_id, }, ) k = dog_obj.write( cr, uid, c.id, {"num_alpha": i.values()[1], "file_setup": a_set_id, "state": "ko"} ) return {}
def _import_attach_plate(self, cr, uid, data, context): content = base64.decodestring(data["form"]["attach"]) list = content.split("\n")[1:] xl = tools.readexcel(file_contents=content) shname = xl.worksheets() sheetnames = [] for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) req_obj = pooler.get_pool(cr.dbname).get("labo.analysis.request") sample_obj = pooler.get_pool(cr.dbname).get("labo.sample") dog_obj = pooler.get_pool(cr.dbname).get("labo.dog") user_obj = pooler.get_pool(cr.dbname).get("res.users") labo_plate_obj = pooler.get_pool(cr.dbname).get("labo.plate") plate_hist_obj = pooler.get_pool(cr.dbname).get("plate.history") setup_obj = pooler.get_pool(cr.dbname).get("analysis.setup") view_b = sample_obj.browse(cr, uid, data["ids"])[0] view_type = view_b.cont if not view_type: view_type = view_b.sample_id.type_id.code flag = "" flag1 = "" a_set_ids = [] user_id = "" for lines in sheetnames: first_lines = lines[:5] last_lines = lines[9:] a = first_lines[0].keys() set_up_n = a[0] != "F1" and a[0] or "" page_number = str(first_lines[0].values()[0]).zfill(4) x1 = first_lines[1].values()[0] date_f = first_lines[2].keys()[0] operat = first_lines[1].values()[0] if operat: user_ids = user_obj.search(cr, uid, [("login", "=", operat)]) if user_ids: user_id = user_ids and user_ids[0] or None # continue till the 5th columns plate_ids = labo_plate_obj.search(cr, uid, [("name", "=", page_number)]) plate_id = plate_ids and plate_ids[0] if not plate_id: plate_id = labo_plate_obj.create(cr, uid, {"name": page_number, "date_p": date_f or None}) for i in last_lines: prog = unicode(i.values()[0]).encode("utf8") # .decode('latin1') if view_type != "EMPDOG" and view_type != "EMPDOG_2" and view_type != "EMPCHE": cr.execute("select id from labo_sample where progenus_number = '%s'" % (prog)) res = cr.fetchall() # ADD HISTORY li = [] for il in res: if il[0]: li.append(il[0]) for r in li: curr_sample = sample_obj.browse(cr, uid, r) if curr_sample and curr_sample.plate_id and (curr_sample.plate_id.name != page_number): jj = plate_hist_obj.create( cr, uid, { "name": time.strftime("%Y-%m-%d"), "sample_id": r, "plate_id2": curr_sample.plate_id.id, "plate_id": plate_id, }, ) k = sample_obj.write(cr, uid, r, {"num_alpha2": i.values()[1], "plate_id": plate_id}) sample_obj.write(cr, uid, r, {"user_id": user_id or None, "state": "ko"}) else: # cr.execute("select l.id from labo_dog d,labo_sample l,labo_plate p where d.progenus_number = '%s' and l.plate_id=p.id and p.name='%s'"%(prog,page_number)) # cr.execute("select l.id from labo_dog d,labo_sample l,labo_plate p where d.progenus_number = '%s' and (l.dog_child=d.id or l.dog_father=d.id or l.dog_mother=d.id)"%(prog)) cr.execute("select d.id from labo_dog d where d.progenus_number = '%s' " % (prog)) res = cr.fetchall() li = [] for il in res: if il[0]: li.append(il[0]) for r in li: curr_dog = dog_obj.browse(cr, uid, r) if curr_dog and curr_dog.plate_id and (curr_dog.plate_id.name != page_number): jj = plate_hist_obj.create( cr, uid, { "name": time.strftime("%Y-%m-%d"), "dog_id1": r, "old_alpha": curr_dog.num_alpha2, "plate_id2": curr_dog.plate_id.id, "plate_id": plate_id, }, ) k = dog_obj.write(cr, uid, r, {"num_alpha2": i.values()[1], "plate_id": plate_id}) sample_obj.write(cr, uid, r, {"user_id": user_id or None, "state": "ko"}) return {}
def _convert_simple_file(self, cr, uid, data, context): sheetnames = [] content = base64.decodestring(data['form']['attach']) xl = tools.readexcel(file_contents=content) shname = xl.worksheets() # header= ["LPNRAP","LPSERV","LPDOSS","LPSEQ","LPENUM","LPENOM","LPENO2","LPEADR","LPELOC","LPRACE","LPFNOM","LPFNUM","LPFTAT","LPFPUC","LPFNOR","LPFDTN","LPFRLB","LPFLLB","LPFNLB","LPFNPR","LPMNOM","LPMNUM","LPMTAT","LPMPUC","LPMNOR","LPMDTN","LPMRLB","LPMLLB","LPMNLB","LPMNPR",'LPCNOM',"LPCSEX","LPCTAT","LPCPUC","LPCDTN","LPCNPR","LPCFIL","LPFILE","LPDTRC","LPNOMT"] fields = {} header = [ "Dossier", "Numpro", "date recpt", "num1", "num2", "num3", "nom", "race", "sexe", "matiere", "dtn", "divers1", "divers2", "preleveur" ] partner_obj = pooler.get_pool(cr.dbname).get('res.partner') req_obj = pooler.get_pool(cr.dbname).get('labo.analysis.request') sample_obj = pooler.get_pool(cr.dbname).get('labo.sample') contact_obj = pooler.get_pool(cr.dbname).get('res.partner.address') type_obj = pooler.get_pool(cr.dbname).get('labo.analysis.type') view_b = sample_obj.browse(cr, uid, data['ids'])[0] view_type = view_b.sample_id.type_id.code # view_type=view_type.upper() num = '' pp = '' flag = '' for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) for lines in sheetnames: for line in lines: if line['Numpro']: fields['progenus_number'] = line['Numpro'] if line['date recpt']: fields['date_reception'] = makeDate(line['date recpt']) or '' fields['identifier_1'] = line['num1'] or None fields['identifier_2'] = line['num2'] or None fields['identifier_3'] = line['num3'] or None fields['name_animal'] = line['nom'] or None fields['breed'] = line['race'] or None fields['sex'] = line['sexe'] or None fields['material'] = line['matiere'] or None fields['birthdate'] = makeDate(line['dtn']) or None fields['misc_1'] = line['divers1'] or None fields['misc_2'] = line['divers2'] or None if line['preleveur']: prelev_id = partner_obj.search( cr, uid, [('name', '=', line['preleveur'])]) if len(prelev_id): fields['preleveur_id'] = prelev_id[0] else: # ADD Eleveur AS A PARTNER new_tatooer = partner_obj.create( cr, uid, {'name': line['preleveur']}) fields['preleveur_id'] = new_tatooer if len(line['Dossier']): # and flag!=line['Dossier']: # if '/' in line['Dossier']: res = line['Dossier'].split('/') if len(res) > 2: num = res[1] + '/' + res[2] type_name = res and res[0] or None type_name = type_name.upper() else: type_name = view_type.upper() type_id_s = type_obj.search(cr, uid, [('code', 'ilike', type_name)]) # CHECK IF REQUEST ALREADY EXITS if num: r_id = req_obj.search(cr, uid, [('name', '=', num), ('type_id', '=', type_id_s[0])]) if len(r_id): request_id = r_id[0] else: request_id = req_obj.create(cr, uid, { 'type_id': type_id_s[0], 'name': num }) flag = line['Dossier'] elif line['Dossier'] and flag == line['Dossier']: request_id = request_id else: has_id = req_obj.search(cr, uid, [('type_id', '=', type_id_s[0]), ('name', '=', '0000/0000')]) request_id = has_id and has_id[0] if not has_id and pp != 'y': request_id = pooler.get_pool( cr.dbname).get('labo.analysis.request').create( cr, uid, { 'type_id': type_id_s[0], 'name': '0000/0000' }) pp = 'y' flag_is = 'yes' else: request_id = request_id fields['sample_id'] = request_id sample_id = sample_obj.create(cr, uid, fields) return {} return {}
def _convert_attach_xsl(self, cr, uid, data, context): content = base64.decodestring(data['form']['attach']) list = content.split('\n')[1:] labo_obj = pooler.get_pool(cr.dbname).get('labo.labo') doss_obj = pooler.get_pool(cr.dbname).get('doss.dog') req_obj = pooler.get_pool(cr.dbname).get('labo.analysis.request') sample_obj = pooler.get_pool(cr.dbname).get('labo.sample') dog_obj = pooler.get_pool(cr.dbname).get('labo.dog') partner_obj = pooler.get_pool(cr.dbname).get('res.partner') contact_obj = pooler.get_pool(cr.dbname).get('res.partner.address') type_obj = pooler.get_pool(cr.dbname).get('labo.analysis.type') seq_obj = pooler.get_pool(cr.dbname).get('ir.sequence') type_id = type_obj.search(cr, uid, [('code', 'ilike', 'EMPDOG')]) type_id_s = type_id and type_id[0] type_id2 = type_obj.search(cr, uid, [('code', 'ilike', 'EMPDOG_2')]) type_id_s2 = type_id2 and type_id2[0] type_id3 = type_obj.search(cr, uid, [('code', 'ilike', 'EMPCHE')]) type_id_s3 = type_id3 and type_id3[0] view_type = '' view_b = sample_obj.browse(cr, uid, data['ids'])[0] view_type = view_b.sample_id.type_id.code flag = '' flag2 = '' flag_f = '' flag_m = '' pp = '' type_a = '' sheetnames = [] nbr = 0 flag1 = '' global sampleids sampleids = [] header = [ "LPNRAP", "LPSERV", "LPDOSS", "LPSEQ", "LPENUM", "LPENOM", "LPENO2", "LPEADR", "LPELOC", "LPRACE", "LPFNOM", "LPFNUM", "LPFTAT", "LPFPUC", "LPFNOR", "LPFDTN", "LPFRLB", "LPFLLB", "LPFNLB", "LPFNPR", "LPMNOM", "LPMNUM", "LPMTAT", "LPMPUC", "LPMNOR", "LPMDTN", "LPMRLB", "LPMLLB", "LPMNLB", "LPMNPR", 'LPCNOM', "LPCSEX", "LPCTAT", "LPCPUC", "LPCDTN", "LPCNPR", "LPCFIL", "LPFILE", "LPDTRC", "LPNOMT" ] fields = {} fields_prelev = ['name', 'code'] flag_is = '' xl = tools.readexcel(file_contents=content) shname = xl.worksheets() num_prog = '' global flag_v flag_v = 'n' for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) i = 0 for lines in sheetnames: for line in lines: try: fields = {} flag_v = 'n' if not len(line): continue view_b = sample_obj.browse(cr, uid, data['ids'])[0] view_type = view_b.sample_id.type_id.code # Try to find prelev s information if line['LPNRAP']: res = line['LPNRAP'].split('/') if len(res) > 2: view_type = res[0] type_id = type_obj.search( cr, uid, [('code', 'ilike', view_type)]) type_id_s = type_id and type_id[0] if view_type.upper() not in ('EMPCHE', 'EMPDOG', 'EMPDOG_2'): raise wizard.except_wizard( 'Error!', 'You are trying to import from a non-complex analysis.\n Try to change the request name %s\n and set its type to EMPCHE, EMPDOG or EMPDOG_2 ' % line['LPNRAP']) if view_type.upper() == "EMPDOG": type_id_s = type_id_s type_a = 'dog' elif view_type.upper() == "EMPDOG_2": type_id_s = type_id_s2 type_a = 'dog' elif view_type.upper() == "EMPCHE": type_id_s = type_id_s3 type_a = 'horse' else: type_a = None view_type = view_type and view_type.upper() # raise wizard.except_wizard('Error!', 'You are trying to import from a non-complex analysis \n Try to set a request name to "%s" \n Or import trough the menu EMPCHE, EMPDOG or EMPDOG_2 '%line['LPFNOR']) if line['LPSERV']: fields['lp_serv'] = line['LPSERV'] try: if line['LPNOTE']: fields['notice'] = line['LPNOTE'] except: raise wizard.except_wizard( 'Error!', 'The column LPNOTE is not your file! \n Please check the structure of your file' ) if line['LPDTRC']: # and len(['LPDTRC'])>3:# and len(line['LPDTRC'])>2: # pri nt "dte", line['LPDTRC'] fields['date_reception'] = _makeDate( line['LPDTRC']) #or '' fields['lp_file'] = line['LPFILE'] try: if line['LPNOMT']: tatoo_id = partner_obj.search( cr, uid, [('name', 'like', line['LPNOMT'])]) if len(tatoo_id): fields['tatooer_id'] = tatoo_id[0] or None else: # ADD Tatooer AS A PARTNER new_tatooer = partner_obj.create( cr, uid, {'name': line['LPNOMT']}) fields['tatooer_id'] = new_tatooer or None except Exception, e: raise wizard.except_wizard( 'Error!', 'The column LPNOMT is not your file! \n Please check the structure of your file: (%s)' % (e, )) continue if line['LPENOM']: prelev_id = partner_obj.search( cr, uid, [('name', '=', line['LPENOM'] + ' ' + (line['LPENO2'] or ''))]) if len(prelev_id): fields['preleveur1_id'] = prelev_id[0] or None elif not line['LPENOM']: fields['preleveur1_id'] = None else: # ADD PRELEVER AS A PARTNER AND "COORDINATES" new_prelev = partner_obj.create( cr, uid, { 'name': line['LPENOM'] + ' ' + (line['LPENO2']), 'ref': line['LPENUM'], }) city_zip = line['LPELOC'].split(' ') zip = '' zip = city_zip[0] city = len( city_zip) == 2 and city_zip[1] and city_zip[1:] or '' new_contact_prelev = contact_obj.create( cr, uid, { 'name': line['LPENOM'] + ' ' + (line['LPENO2'] or ''), 'city': city and city[0].replace('"', ''), 'street': line['LPEADR'], 'zip': zip and zip.replace('"', ''), 'partner_id': new_prelev }) fields['preleveur1_id'] = new_prelev or None # CREATE FEMALE DOG # SEARCH AND CREATE LABO INFORMATION IF NOT EXISTING labo_femal_id = '' dogfemal_id = '' if line['LPFNPR'] and str(line['LPFNPR']) != '0': num_prog = line['LPFNPR'] code_femal = line['LPFNLB'] if str(line['LPFNLB']) == '0': code_femal = '1' labofemal_id = labo_obj.search(cr, uid, [('code', '=', code_femal)]) if len(labofemal_id): labo_femal_id = labofemal_id[0] elif line['LPFNLB'] and int(line['LPFNLB']) > 0: new_labo_f = labo_obj.create( cr, uid, { 'name': line['LPFLLB'], # 'ref':line['LPFRLB'], 'code': line['LPFNLB'], }) labo_femal_id = new_labo_f # Use progenus number or origin number to find femal dog flag2 = '' ##CHECK CONDITION TO SET if line['LPFNPR'] and str(line['LPFNPR']) != '0': num_prog = line['LPFNPR'] dogfemal_id = '' flag2 = '' if (view_type == "EMPCHE" or view_type == "EMPDOG" or view_type == "EMPDOG_2") and flag2 != 'y': num_prog = line['LPFNPR'] if line['LPFNOM'] and str( line['LPFNOM'].encode('utf-8')) != '0' and ( not dogfemal_id or dogfemal_id == None) and view_type == "EMPCHE": dogfemal_id = dog_obj.search( cr, uid, [('name', '=', line['LPFNOM'].encode('utf-8'))]) dogfemal_id.sort(reverse=True) dogfemal_id = dogfemal_id and dogfemal_id[0] flag2 = 'y' if line['LPFNPR'] and (not dogfemal_id or dogfemal_id == None): dogfemal_id = dog_obj.search( cr, uid, [('progenus_number', '=', line['LPFNPR'])]) dogfemal_id.sort(reverse=True) dogfemal_id = dogfemal_id and dogfemal_id[0] if line['LPFNOR'] and (not dogfemal_id or dogfemal_id == None): dogfemal_id = dog_obj.search( cr, uid, [('origin', '=', line['LPFNOR'])]) dogfemal_id.sort(reverse=True) dogfemal_id = dogfemal_id and dogfemal_id[0] if dogfemal_id: num_tmp = dog_obj.browse(cr, uid, dogfemal_id).progenus_number if not num_tmp and line['LPFNPR'] and line[ 'LPFNPR'] and str(line['LPFNPR']) != '0': dog_obj.write(cr, uid, [dogfemal_id], {'progenus_number': line['LPFNPR']}) if num_tmp and line['LPFNPR'] and str( line['LPFNPR']) != '0' and num_tmp != str( line['LPFNPR']): dogfemal_id = '' if (not (dogfemal_id) or dogfemal_id == None) and line['LPFNOM'].encode( 'utf8') and line['LPFNOM'].encode( 'utf-8') != '0': # or not line['LPMNPR']: dogfemal_id = dog_obj.create( cr, uid, { 'name': line['LPFNOM'].encode('utf-8'), 'progenus_number': num_prog or None, 'origin': line['LPFNOR'], 'tatoo': line['LPFTAT'], 'sex': 'F', 'ref_dog': line['LPFRLB'], 'race': line['LPRACE'], 'birthdate': _makeDate(line['LPFDTN']), 'ship': line['LPFPUC'], 'pedigree': line['LPFNUM'] or None, 'type_animal': type_a, }) if labo_femal_id: if dogfemal_id and dogfemal_id != None: dog_obj.write(cr, uid, [dogfemal_id], {'labo_id': labo_femal_id}) if dogfemal_id and dogfemal_id != None: # if view_type=="EMPDOG_2": # flag_v='YES' fields['dog_mother'] = dogfemal_id or None if str(line['LPFNLB']) == '1': dog_obj.write(cr, uid, [dogfemal_id], {'done_i': True}) doss_obj.create(cr, uid, { 'name': line['LPDOSS'], 'dog_id1': dogfemal_id }) # else: # fields['dog_mother']= None #don t need this part # if line['LPFNOM'] and view_type!='EMPCHE' and view_type!="EMPDOG" and view_type!="EMPDOG_2": # if line['LPFNPR'] and str(line['LPFNPR']!='0'): # dogfemal_id=dog_obj.search(cr,uid,[('progenus_number','=',line['LPFNPR'])]) # dogfemal_id=dogfemal_id and dogfemal_id[0] # flag2='y' # if line['LPMNOR'] and (not dogfemal_id or dogfemal_id==None): # dogfemal_id=dog_obj.search(cr,uid,[('origin','=',line['LPFNOR'])]) # dogfemal_id=dogfemal_id and dogfemal_id[0] # # # flag2='y' # # if not line['LPFNPR'] and str(line['LPFNPR'])!='0' or flag2=='y': # # dogfemal_id=dog_obj.search(cr,uid,[('origin','=',line['LPFNOR'])]) # # dogfemal_id=dogfemal_id and dogfemal_id[0] # # if (not(dogfemal_id) or dogfemal_id==None) and line['LPFNOM']:# or not line['LPFNPR'] or line['LPFNPR']=='0': # dogfemal_id=dog_obj.create(cr,uid,{'name':line['LPFNOM'], # 'progenus_number':num_prog, # 'origin':line['LPFNOR'], # 'tatoo':line['LPFTAT'], # 'sex':'F', # 'race':line['LPRACE'], # 'birthdate':_makeDate(line['LPFDTN']) or None, # 'ship':line['LPFPUC'], # 'pedigree':line['LPFNUM'], # 'type_animal':type_a, # # 'labo_id':labo_m_id # }) # if labo_femal_id: # dog_obj.write(cr,uid,[dogfemal_id],{'labo_id':labo_femal_id}) # # # fields['dog_mother']=dogfemal_id #end unusef ul code # CREATE MALE DOG # SEARCH AND CREATE LABO INFORMATION IF NOT exist code_mal = line['LPMNLB'] if str(line['LPMNLB']) == '0': code_mal = '1' labomal_id = labo_obj.search(cr, uid, [('code', '=', code_mal)]) labo_mal_id = '' dogmal_id = '' num_prog = line['LPMNPR'] if len(labomal_id): labo_mal_id = labomal_id[0] elif line['LPMLLB'] and line['LPMNLB'] and int( line['LPMNLB']) > 0: new_labo_d = labo_obj.create( cr, uid, { 'name': line['LPMLLB'], # 'ref':line['LPMRLB'], 'code': line['LPMNLB'], }) # Use progenus number or origin number to find mal dog labo_mal_id = new_labo_d flag3 = '' if line['LPMNPR'] and str(line['LPMNPR']) != '0': num_prog = line['LPMNPR'] dogmal_id = '' # if view_type=="EMPDOG_2" and flag_v=='YES': # fields['dog_father']=None if (view_type == "EMPCHE" or view_type == "EMPDOG" or view_type == "EMPDOG_2") and flag3 != 'y': # if view_type=="EMPCHE" and flag3!='y': num_prog = line['LPMNPR'] if (line['LPMNOM'] and str(line['LPMNOM'].encode('utf-8')) != '0') and (not dogmal_id or dogmal_id == None) and view_type == "EMPCHE": dogmal_id = dog_obj.search( cr, uid, [('name', '=', line['LPMNOM'].encode('utf)8'))]) dogmal_id.sort(reverse=True) dogmal_id = dogmal_id and dogmal_id[0] flag3 = 'y' if line['LPMNPR'] and (not dogmal_id or dogmal_id == None): dogmal_id = dog_obj.search( cr, uid, [('progenus_number', '=', line['LPMNPR'])]) dogmal_id.sort(reverse=True) dogmal_id = dogmal_id and dogmal_id[0] if line['LPMNOR'] and (not dogmal_id or dogmal_id == None): dogmal_id = dog_obj.search( cr, uid, [('origin', '=', line['LPMNOR'])]) dogmal_id.sort(reverse=True) dogmal_id = dogmal_id and dogmal_id[0] if dogmal_id: num_tmp = dog_obj.browse(cr, uid, dogmal_id).progenus_number if not num_tmp and line['LPMNPR'] and str( line['LPMNPR']) != '0': dog_obj.write(cr, uid, [dogmal_id], {'progenus_number': line['LPMNPR']}) if num_tmp and line['LPMNPR'] and str( line['LPMNPR']) != '0' and num_tmp != str( line['LPMNPR']): dogmal_id = '' # if dogmal_id: if (not (dogmal_id) or dogmal_id == None ) and line['LPMNOM'].encode('utf)8') and line[ 'LPMNOM'] != '0': # or not line['LPMNPR']: dogmal_id = dog_obj.create( cr, uid, { 'name': line['LPMNOM'].encode('utf-8'), 'progenus_number': num_prog, 'origin': line['LPMNOR'], 'tatoo': line['LPMTAT'], 'sex': 'M', 'race': line['LPRACE'], 'ref_dog': line['LPMRLB'], 'birthdate': _makeDate(line['LPMDTN']), 'ship': line['LPMPUC'], 'pedigree': line['LPMNUM'] or None, 'type_animal': type_a, }) if labo_mal_id and labo_mal_id != None and dogmal_id: dog_obj.write(cr, uid, [dogmal_id], {'labo_id': labo_mal_id or None}) if dogmal_id and dogmal_id != None and len(str(dogmal_id)): # if flag_v!='YES':# and view_type=="EMPDOG_2": fields['dog_father'] = dogmal_id or None if str(line['LPMNLB']) == '1': dog_obj.write(cr, uid, [dogmal_id], {'done_i': True}) doss_obj.create(cr, uid, { 'name': line['LPDOSS'], 'dog_id1': dogmal_id }) # else: # fields['dog_father']=None # if line['LPMNOM'] and view_type!='EMPCHE': # if line['LPMNPR'] and str(line['LPMNPR'])!='0': # dogmal_id=dog_obj.search(cr,uid,[('progenus_number','=',line['LPMNPR'])]) # dogmal_id=dogmal_id and dogmal_id[0] # flag3='y' # if not line['LPMNPR'] or flag3=='y': # dogmal_id=dog_obj.search(cr,uid,[('origin','=',line['LPMNOR'])]) # dogmal_id=dogmal_id and dogmal_id[0] # if not(dogmal_id) and line['LPMNOM']:# or not line['LPMNPR']: # dogmal_id=dog_obj.create(cr,uid,{'name':line['LPMNOM'], # 'progenus_number':num_prog, # 'origin':line['LPMNOR'], # 'tatoo':line['LPMTAT'], # 'sex':'M', # 'race':line['LPRACE'], # 'birthdate':_makeDate(line['LPMDTN']), # 'ship':line['LPMPUC'], # 'pedigree':line['LPMNUM'] or None, # 'type_animal':type_a, # }) # if labo_mal_id: # dog_obj.write(cr,uid,[dogmal_id],{'labo_id':labo_mal_id}) # fields['dog_father']=dogmal_id if line['LPDOSS']: fields['lp_doss'] = line['LPDOSS'] if line['LPCFIL']: fields['res_filiation'] = line['LPCFIL'] # CREATE PUPPY # SEARCH AND CREATE PROGENUS LABO INFORMATION labop_id = labo_obj.search(cr, uid, [('code', '=', 1)]) if len(labop_id): labo_p_id = labop_id[0] else: new_labo_p = labo_obj.create(cr, uid, { 'name': 'Progenus', 'ref': '1', 'code': '1', }) labo_p_id = new_labo_p # SEARCH PUPPY puppy_id = '' if view_type == "EMPCHE": try: name = line['LPCNOM'].encode('utf-8') except: raise wizard.except_wizard( 'Error!', 'The column LPCNOM is not your file! \n Please check the structure of your file' ) if line['LPCNOM'] and str( line['LPCNOM'].encode('utf-8')) != '0' and ( not puppy_id or puppy_id == None): puppy_id = dog_obj.search( cr, uid, [('name', '=', line['LPCNOM'].encode('utf-8'))]) puppy_id = puppy_id and puppy_id[0] flag2 = 'y' if line['LPCNPR'] and str(line['LPCNPR']) != '0': puppy_id = dog_obj.search( cr, uid, [('progenus_number', '=', line['LPCNPR'])]) puppy_id = puppy_id and puppy_id[0] # compare using sequence and DOSS if not puppy_id or puppy_id == None: m_id = dog_obj.search(cr, uid, [ ('name', '=', line['LPMNOM'].encode('utf-8')) ]) f_id = dog_obj.search(cr, uid, [ ('name', '=', line['LPFNOM'].encode('utf-8')) ]) a = m_id and m_id[0] b = f_id and f_id[0] if not len(f_id): f_id = dog_obj.search( cr, uid, [('tatoo', '=', line['LPFTAT'])]) else: f_id = dog_obj.search( cr, uid, [('origin', '=', line['LPFNOR'])]) b = f_id and f_id[0] if not len(m_id): m_id = dog_obj.search( cr, uid, [('tatoo', '=', line['LPMTAT'])]) else: m_id = dog_obj.search( cr, uid, [('origin', '=', line['LPMNOR'])]) a = m_id and m_id[0] if a and a != None and b and b != None: cr.execute( "SELECT id from labo_dog where parent_f_id=%d and parent_m_id=%d" % (a, b)) res = cr.fetchone() puppy_id = res and res[0] else: num_prog = line['LPCNPR'] flag1 = 'y' if not puppy_id or puppy_id == None: # find mum of child m_id = dog_obj.search( cr, uid, [('name', '=', line['LPMNOM'].encode('utf-8'))]) f_id = dog_obj.search( cr, uid, [('name', '=', line['LPFNOM'].encode('utf-8'))]) a = m_id and m_id[0] b = f_id and f_id[0] if a and a != None and b and b != None: cr.execute( "SELECT id from labo_dog where parent_f_id=%d and parent_m_id=%d" % (a, b)) res = cr.fetchone() puppy_id = res and res[0] try: name = line['LPCNOM'].encode('utf-8') except: raise wizard.except_wizard( 'Error!', 'The column LPCNOM is not your file! \n Please check the structure of your file' ) if puppy_id and line['LPCNPR'] and str( line['LPCNPR']) != '0': num_p = dog_obj.browse(cr, uid, puppy_id).progenus_number if not num_p and line['LPCNPR']: dog_obj.write( cr, uid, [puppy_id], {'progenus_number': line['LPCNPR']}) if num_p and line['LPCNPR'] and num_p != str( line['LPCNPR']): puppy_id = '' if not puppy_id or puppy_id == None: puppy_id = dog_obj.create( cr, uid, { 'name': line['LPCNOM'].encode('utf-8'), 'progenus_number': str(line['LPCNPR']) != '0' and line['LPCNPR'], # 'seq':line['LPSEQ'], 'tatoo': line['LPCTAT'], 'sex': line['LPCSEX'], 'race': line['LPRACE'], 'birthdate': _makeDate(line['LPCDTN']), 'ship': line['LPCPUC'], 'parent_m_id': dogfemal_id or None, 'parent_f_id': dogmal_id or None, 'labo_id': labo_p_id or None, 'type_animal': type_a, }) if puppy_id and puppy_id != None: fields['dog_child'] = puppy_id #dog_obj.write(cr,uid, [puppy_id], {'done_i':True}) doss_obj.create(cr, uid, { 'name': line['LPDOSS'] or None, 'dog_id1': puppy_id }) if line['LPSEQ']: fields['seq_horse'] = line['LPSEQ'] puppy_id = '' if view_type == "EMPDOG": # ##1 # if line['LPCNOM'] and str(line['LPCNOM'].encode('utf-8'))!='0' and (not puppy_id or puppy_id==None): # puppy_id=dog_obj.search(cr,uid,[('name','=',line['LPCNOM'].encode('utf-8'))]) # puppy_id=puppy_id and puppy_id[0] or None # #END of 1 if line['LPCNPR'] and str(line['LPCNPR']) != '0' and ( not puppy_id or puppy_id == None): puppy_id = dog_obj.search( cr, uid, [('progenus_number', '=', line['LPCNPR'])]) puppy_id = puppy_id and puppy_id[0] # compare using sequence and DOSS if not puppy_id: m_id = dog_obj.search( cr, uid, [('origin', '=', line['LPMNOR'])]) f_id = dog_obj.search( cr, uid, [('origin', '=', line['LPFNOR'])]) a = m_id and m_id[0] b = f_id and f_id[0] c = int(line['LPSEQ']) cr.execute( "SELECT id from labo_dog where seq=%d and parent_f_id=%d and parent_m_id=%d" % (c, a, b)) res = cr.fetchone() puppy_id = res and res[0] else: num_prog = line['LPCNPR'] flag1 = 'y' if not (line['LPCNPR']) or str(line['LPCNPR']) == '0' and ( not (puppy_id) or puppy_id == None): # find mum of child m_id = dog_obj.search( cr, uid, [('origin', '=', line['LPMNOR'])]) f_id = dog_obj.search( cr, uid, [('origin', '=', line['LPFNOR'])]) a = m_id and m_id[0] b = f_id and f_id[0] c = line['LPSEQ'] and int(line['LPSEQ']) if a and a != None and b and b != None and c and c != None: cr.execute( "SELECT id from labo_dog where seq=%d and parent_f_id=%d and parent_m_id=%d" % (c, b, a)) res = cr.fetchone() puppy_id = res and res[0] if puppy_id and line['LPCNPR'] and str( line['LPCNPR']) != '0': num_p = dog_obj.browse(cr, uid, puppy_id).progenus_number if not num_p and line['LPCNPR']: dog_obj.write(cr, uid, [puppy_id], {'progenus_number': line['LPCNPR']}) if num_p and num_p != str(line['LPCNPR']): puppy_id = '' if (line['LPCNPR']) and str( line['LPCNPR'] ) == '0' and puppy_id == None or not puppy_id: # num_prog=line['LPCNPR'] # if not puppy_id or puppy_id==None: puppy_id = dog_obj.create( cr, uid, { # 'name':line['LPCNOM'], 'progenus_number': line['LPCNPR'], 'seq': line['LPSEQ'], 'tatoo': line['LPCTAT'], 'sex': line['LPCSEX'], 'race': line['LPRACE'], 'birthdate': _makeDate(line['LPCDTN']), 'ship': line['LPCPUC'], 'parent_m_id': dogfemal_id or None, 'parent_f_id': dogmal_id or None, 'labo_id': labo_p_id, 'type_animal': type_a, }) if puppy_id and puppy_id != None: fields['dog_child'] = puppy_id # dog_obj.write(cr,uid, [puppy_id], {'done_i':True}) doss_obj.create(cr, uid, { 'name': line['LPDOSS'] or None, 'dog_id1': puppy_id }) flag1 = '' # SET A REQUEST # REQUEST FILLED IN THE ATTACHMENT if line['LPNRAP']: # and flag!=line['LPNRAP']: res = line['LPNRAP'].split('/') if len(res) > 2: num = res[1] + '/' + res[2] # CHECK IF REQUEST ALREADY EXITS if res[0]: view_type = res[0] type_id = type_obj.search( cr, uid, [('code', 'ilike', view_type)]) type_id_s = type_id and type_id[0] elif view_type == "EMPDOG": type_id_s = type_id_s elif view_type == "EMPDOG_2": type_id_s = type_id_s2 elif view_type == "EMPCHE": type_id_s = type_id_s3 r_id = req_obj.search(cr, uid, [('name', '=', num), ('type_id', '=', type_id_s)]) if len(r_id): request_id = r_id[0] else: request_id = req_obj.create(cr, uid, { 'type_id': type_id_s, 'name': num }) flag = line['LPNRAP'] elif line['LPNRAP'] and flag == line['LPNRAP']: request_id = request_id else: has_id = req_obj.search(cr, uid, [('type_id', '=', type_id_s), ('name', '=', '0000/0000')]) request_id = has_id and has_id[0] if not has_id and pp != 'y': request_id = pooler.get_pool( cr.dbname).get('labo.analysis.request').create( cr, uid, { 'type_id': type_id_s, 'name': '0000/0000' }) pp = 'y' flag_is = 'yes' else: request_id = request_id fields['sample_id'] = request_id or None sample_id = sample_obj.create(cr, uid, fields) sampleids.append(sample_id) except Exception, e: raise wizard.except_wizard( 'Error!', '%s \n The problem is coming from this line! Please check its content \n \n %s' % ( e, line.values(), ))
def _convert_attach_xsl(self, cr, uid, data, context=None): fields = {} content = base64.decodestring(data['form']['attach']) list = content.split('\n')[1:] labo_obj = pooler.get_pool(cr.dbname).get('labo.labo') req_obj = pooler.get_pool(cr.dbname).get('labo.analysis.request') type_obj = pooler.get_pool(cr.dbname).get('labo.analysis.type') sample_obj = pooler.get_pool(cr.dbname).get('labo.sample') dog_obj = pooler.get_pool(cr.dbname).get('labo.dog') seq_obj = pooler.get_pool(cr.dbname).get('ir.sequence') dict_s = {} dict_s2 = {} max_v = '' j = 0 type_id = type_obj.search(cr, uid, [('code', 'ilike', 'EMPDOG')]) sheetnames = [] xl = tools.readexcel(file_contents=content) shname = xl.worksheets() for sh in shname: a = xl.getiter(sh) sheet_items = [] for row in a: if len([i for i in row.values() if i]): sheet_items.append(row) sheetnames.append(sheet_items) for lines in sheetnames: for line in lines: dict_s[line['LPDOSS'], line['LPSEQ']] = (line['LPNRAP'], line['LPFNPR'], line['LPMNPR'], line['LPCSEX'], line['LPCTAT'], line['LPCPUC'], line['LPCNPR'], line['LPCFIL'], line['LPDTRC']) v_tmp = line['LPNRAP'].split('/') if len(v_tmp) > 2: v_name = v_tmp[1] + '/' + v_tmp[2] dict_s2[line['LPDOSS']] = (v_name) infos_dict = dict_s.keys() flag = '' flag_is = '' flag1 = '' list_doss = [] a = [] flag_quit = '' flag_r = '' flag_ss = '' dict_p = {} i = 0 k = sample_obj.browse(cr, uid, data['ids']) cr.execute( "SELECT number_next,code from ir_sequence where prefix like 'cc'") res_cr1 = cr.fetchone() cr.execute( "SELECT number_next,code from ir_sequence where prefix like 'che'") res_cr2 = cr.fetchone() while i < len(dict_s.keys()): infos_dict = dict_s.keys()[i] # cr.execute("select s.id,s.dog_child,s.dog_mother,s.dog_father,r.id from labo_dog d, labo_analysis_request r, labo_sample s where s.sample_id=r.id and d.id=s.dog_child and d.seq=%d and s.lp_doss=%d"%(int(infos_dict[1]), int(infos_dict[0])) ) cr.execute( "select s.id,s.dog_child,s.dog_mother,s.dog_father,r.id from labo_dog d, labo_analysis_request r, labo_sample s where d.seq=%d and s.lp_doss=%d and s.id in %s" % (int(infos_dict[1]), int( infos_dict[0]), "(" + ",".join(map(str, data['ids'])) + ")")) res = cr.fetchone() # UPDATE SAMPLES WITH RESULTS # RECEPTION DATE if res and res[0]: print "res", res[0] sample_obj.write( cr, uid, [res[0]], { 'date_reception': _makeDate(dict_s.values()[i][8]) or None, 'res_filiation': (dict_s.values()[i][7]) or None }) # fill fields puppy puppy_id = res and res[1] print "res1", res[1], dict_s.values()[i][3] if puppy_id and puppy_id != None: dog_obj.write( cr, uid, [puppy_id], { 'tatoo': (dict_s.values()[i][4]) or None, 'ship': (dict_s.values()[i][5]) or None, 'sex': (dict_s.values()[i][3]) or None, }) if dict_s.values()[i][6] and str(dict_s.values()[i][6]) != '0': prog_num = dict_s.values()[i][6] dog_obj.write(cr, uid, [puppy_id], {'progenus_number': prog_num}) # fill fields mother mother_id = res and res[2] # if mother_id : # if dict_s.values()[i][1] and str(dict_s.values()[i][1])!='0': # prog_num=dict_s.values()[i][1] # prog_num=seq_obj.get(cr,uid,res_cr1[1]) # dog_obj.write(cr,uid,[mother_id],{'progenus_number':prog_num}) # fill fields father father_id = res and res[3] if father_id: if dict_s.values()[i][2] and str(dict_s.values()[i][2]) != '0': prog_num = dict_s.values()[i][2] dog_obj.write(cr, uid, [father_id], {'progenus_number': prog_num}) # fill name of request req_id = res and res[4] i += 1 # REQUEST NUMBER FILLED IN ATTACHMENT # use dict_s2 # check if request exists for val in dict_s2.keys(): rek_id = '' flag_r = '' cr.execute("select id from labo_sample where lp_doss=%d" % (int(val))) ids_s = cr.fetchall() ids_res = ids_s and ids_s[0] for it in ids_s: cr.execute( "select r.id from labo_analysis_request r, labo_analysis_type t where t.id=r.type_id and r.name like '%s' and t.code ilike 'EMPDOG'" % (dict_s2[val])) res_r = cr.fetchone() it_id = ",".join([str(x) for x in it if x]) if not res_r and flag_r != 'y': flag_r = 'y' rek_id = req_obj.create(cr, uid, { 'name': dict_s2[val], 'type_id': type_id and type_id[0] }) elif res_r: res_k = res_r and res_r[0] rek_id = res_k sample_obj.write(cr, uid, [int(it_id)], {'sample_id': rek_id}) return {}