Merge lp:~openerp-commiter/openobject-server/5.0-opw-4592-dhs into lp:openobject-server/5.0

Proposed by Dhruti Shastri(OpenERP)
Status: Merged
Merged at revision: 2174
Proposed branch: lp:~openerp-commiter/openobject-server/5.0-opw-4592-dhs
Merge into: lp:openobject-server/5.0
Diff against target: 526 lines (+94/-92)
1 file modified
bin/osv/orm.py (+94/-92)
To merge this branch: bzr merge lp:~openerp-commiter/openobject-server/5.0-opw-4592-dhs
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+55468@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Dhruti,

Kindly by the next time, take care of those unnecessary whitespaces.

Thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/osv/orm.py'
--- bin/osv/orm.py 2011-02-04 09:32:33 +0000
+++ bin/osv/orm.py 2011-03-30 04:57:36 +0000
@@ -388,7 +388,7 @@
388 #setting value to let the problem NOT occur next time388 #setting value to let the problem NOT occur next time
389 elif k in cols:389 elif k in cols:
390 vals['select_level'] = cols[k]['select_level']390 vals['select_level'] = cols[k]['select_level']
391 391
392 if k not in cols:392 if k not in cols:
393 cr.execute('select nextval(%s)', ('ir_model_fields_id_seq',))393 cr.execute('select nextval(%s)', ('ir_model_fields_id_seq',))
394 id = cr.fetchone()[0]394 id = cr.fetchone()[0]
@@ -468,10 +468,10 @@
468 return 0.0468 return 0.0
469 elif field_type == 'integer':469 elif field_type == 'integer':
470 return 0470 return 0
471 elif field_type == 'boolean': 471 elif field_type == 'boolean':
472 return False 472 return False
473 return ''473 return ''
474 474
475 def selection_field(in_field):475 def selection_field(in_field):
476 col_obj = self.pool.get(in_field.keys()[0])476 col_obj = self.pool.get(in_field.keys()[0])
477 if f[i] in col_obj._columns.keys():477 if f[i] in col_obj._columns.keys():
@@ -479,20 +479,20 @@
479 elif f[i] in col_obj._inherits.keys():479 elif f[i] in col_obj._inherits.keys():
480 selection_field(col_obj._inherits)480 selection_field(col_obj._inherits)
481 else:481 else:
482 return False 482 return False
483 483
484 lines = []484 lines = []
485 data = map(lambda x: '', range(len(fields)))485 data = map(lambda x: '', range(len(fields)))
486 done = []486 done = []
487 for fpos in range(len(fields)):487 for fpos in range(len(fields)):
488 f = fields[fpos] 488 f = fields[fpos]
489 if f:489 if f:
490 r = row490 r = row
491 i = 0491 i = 0
492 while i < len(f):492 while i < len(f):
493 if f[i] == 'db_id':493 if f[i] == 'db_id':
494 r = r['id'] 494 r = r['id']
495 elif f[i] == 'id': 495 elif f[i] == 'id':
496 model_data = self.pool.get('ir.model.data')496 model_data = self.pool.get('ir.model.data')
497 data_ids = model_data.search(cr, uid, [('model','=',r._table_name),('res_id','=',r['id'])])497 data_ids = model_data.search(cr, uid, [('model','=',r._table_name),('res_id','=',r['id'])])
498 if len(data_ids):498 if len(data_ids):
@@ -506,7 +506,7 @@
506 else:506 else:
507 r = r[f[i]]507 r = r[f[i]]
508 # To display external name of selection field when its exported508 # To display external name of selection field when its exported
509 if not context.get('import_comp',False):# Allow external name only if its not import compatible 509 if not context.get('import_comp',False):# Allow external name only if its not import compatible
510 cols = False510 cols = False
511 if f[i] in self._columns.keys():511 if f[i] in self._columns.keys():
512 cols = self._columns[f[i]]512 cols = self._columns[f[i]]
@@ -518,11 +518,11 @@
518 r = [x[1] for x in sel_list if r==x[0]]518 r = [x[1] for x in sel_list if r==x[0]]
519 r = r and r[0] or False519 r = r and r[0] or False
520 if not r:520 if not r:
521 if f[i] in self._columns: 521 if f[i] in self._columns:
522 r = check_type(self._columns[f[i]]._type)522 r = check_type(self._columns[f[i]]._type)
523 elif f[i] in self._inherit_fields:523 elif f[i] in self._inherit_fields:
524 r = check_type(self._inherit_fields[f[i]][2]._type) 524 r = check_type(self._inherit_fields[f[i]][2]._type)
525 data[fpos] = r 525 data[fpos] = r
526 break526 break
527 if isinstance(r, (browse_record_list, list)):527 if isinstance(r, (browse_record_list, list)):
528 first = True528 first = True
@@ -531,10 +531,10 @@
531 if fields2 in done:531 if fields2 in done:
532 if [x for x in fields2 if x]:532 if [x for x in fields2 if x]:
533 break533 break
534 done.append(fields2) 534 done.append(fields2)
535 for row2 in r:535 for row2 in r:
536 lines2 = self.__export_row(cr, uid, row2, fields2,536 lines2 = self.__export_row(cr, uid, row2, fields2,
537 context) 537 context)
538 if first:538 if first:
539 for fpos2 in range(len(fields)):539 for fpos2 in range(len(fields)):
540 if lines2 and lines2[0][fpos2]:540 if lines2 and lines2[0][fpos2]:
@@ -542,17 +542,19 @@
542 if not data[fpos]:542 if not data[fpos]:
543 dt = ''543 dt = ''
544 for rr in r :544 for rr in r :
545 if isinstance(rr.name, browse_record):545 rr_name = ''
546 rr = rr.name546 if rr.name:
547 rr_name = self.pool.get(rr._table_name).name_get(cr, uid, [rr.id], context=context)547 if isinstance(rr.name, browse_record):
548 rr_name = rr_name and rr_name[0] and rr_name[0][1] or ''548 rr = rr.name
549 rr_name = self.pool.get(rr._table_name).name_get(cr, uid, [rr.id], context=context)
550 rr_name = rr_name and rr_name[0] and rr_name[0][1] or ''
549 dt += tools.ustr(rr_name or '') + ','551 dt += tools.ustr(rr_name or '') + ','
550 data[fpos] = dt[:-1]552 data[fpos] = dt[:-1]
551 break553 break
552 lines += lines2[1:]554 lines += lines2[1:]
553 first = False555 first = False
554 else:556 else:
555 lines += lines2 557 lines += lines2
556 break558 break
557 i += 1559 i += 1
558 if i == len(f):560 if i == len(f):
@@ -565,14 +567,14 @@
565 def export_data(self, cr, uid, ids, fields_to_export, context=None):567 def export_data(self, cr, uid, ids, fields_to_export, context=None):
566 if not context:568 if not context:
567 context = {}569 context = {}
568 imp_comp = context.get('import_comp',False) 570 imp_comp = context.get('import_comp',False)
569 cols = self._columns.copy()571 cols = self._columns.copy()
570 for f in self._inherit_fields:572 for f in self._inherit_fields:
571 cols.update({f: self._inherit_fields[f][2]}) 573 cols.update({f: self._inherit_fields[f][2]})
572 fields_to_export = map(lambda x: x.split('/'), fields_to_export)574 fields_to_export = map(lambda x: x.split('/'), fields_to_export)
573 fields_export = fields_to_export+[] 575 fields_export = fields_to_export+[]
574 warning = '' 576 warning = ''
575 warning_fields = [] 577 warning_fields = []
576 for field in fields_export:578 for field in fields_export:
577 if imp_comp and len(field)>1:579 if imp_comp and len(field)>1:
578 warning_fields.append('/'.join(map(lambda x:x in cols and cols[x].string or x,field)))580 warning_fields.append('/'.join(map(lambda x:x in cols and cols[x].string or x,field)))
@@ -580,11 +582,11 @@
580 if imp_comp and cols.get(field and field[0],False):582 if imp_comp and cols.get(field and field[0],False):
581 if ((isinstance(cols[field[0]], fields.function) and not cols[field[0]].store) \583 if ((isinstance(cols[field[0]], fields.function) and not cols[field[0]].store) \
582 or isinstance(cols[field[0]], fields.related)\584 or isinstance(cols[field[0]], fields.related)\
583 or isinstance(cols[field[0]], fields.one2many)): 585 or isinstance(cols[field[0]], fields.one2many)):
584 warning_fields.append('/'.join(map(lambda x:x in cols and cols[x].string or x,field)))586 warning_fields.append('/'.join(map(lambda x:x in cols and cols[x].string or x,field)))
585 datas = []587 datas = []
586 if imp_comp and len(warning_fields):588 if imp_comp and len(warning_fields):
587 warning = 'Following columns cannot be exported since you select to be import compatible.\n%s' %('\n'.join(warning_fields)) 589 warning = 'Following columns cannot be exported since you select to be import compatible.\n%s' %('\n'.join(warning_fields))
588 cr.rollback()590 cr.rollback()
589 return {'warning' : warning}591 return {'warning' : warning}
590 for row in self.browse(cr, uid, ids, context):592 for row in self.browse(cr, uid, ids, context):
@@ -597,14 +599,14 @@
597 fields = map(lambda x: x.split('/'), fields)599 fields = map(lambda x: x.split('/'), fields)
598 logger = netsvc.Logger()600 logger = netsvc.Logger()
599 ir_model_data_obj = self.pool.get('ir.model.data')601 ir_model_data_obj = self.pool.get('ir.model.data')
600 602
601 def _check_db_id(self, model_name, db_id):603 def _check_db_id(self, model_name, db_id):
602 obj_model = self.pool.get(model_name)604 obj_model = self.pool.get(model_name)
603 ids = obj_model.search(cr, uid, [('id','=',int(db_id))])605 ids = obj_model.search(cr, uid, [('id','=',int(db_id))])
604 if not len(ids):606 if not len(ids):
605 raise Exception(_("Database ID doesn't exist: %s : %s") %(model_name, db_id))607 raise Exception(_("Database ID doesn't exist: %s : %s") %(model_name, db_id))
606 return True608 return True
607 609
608 def process_liness(self, datas, prefix, current_module, model_name, fields_def, position=0):610 def process_liness(self, datas, prefix, current_module, model_name, fields_def, position=0):
609 line = datas[position]611 line = datas[position]
610 row = {}612 row = {}
@@ -624,25 +626,25 @@
624 raise Exception(_('Please check that all your lines have %d columns.') % (len(fields),))626 raise Exception(_('Please check that all your lines have %d columns.') % (len(fields),))
625 if not line[i]:627 if not line[i]:
626 continue628 continue
627 629
628 field = fields[i]630 field = fields[i]
629 if prefix and not prefix[0] in field:631 if prefix and not prefix[0] in field:
630 continue632 continue
631 633
632 if (len(field)==len(prefix)+1) and field[len(prefix)].endswith(':db_id'):634 if (len(field)==len(prefix)+1) and field[len(prefix)].endswith(':db_id'):
633 # Database ID635 # Database ID
634 res = False636 res = False
635 if line[i]:637 if line[i]:
636 field_name = field[0].split(':')[0]638 field_name = field[0].split(':')[0]
637 model_rel = fields_def[field_name]['relation'] 639 model_rel = fields_def[field_name]['relation']
638 640
639 if fields_def[field[len(prefix)][:-6]]['type']=='many2many':641 if fields_def[field[len(prefix)][:-6]]['type']=='many2many':
640 res_id = []642 res_id = []
641 for db_id in line[i].split(config.get('csv_internal_sep')):643 for db_id in line[i].split(config.get('csv_internal_sep')):
642 try:644 try:
643 _check_db_id(self, model_rel, db_id)645 _check_db_id(self, model_rel, db_id)
644 res_id.append(db_id)646 res_id.append(db_id)
645 except Exception,e: 647 except Exception,e:
646 warning += [tools.exception_to_unicode(e)]648 warning += [tools.exception_to_unicode(e)]
647 logger.notifyChannel("import", netsvc.LOG_ERROR,649 logger.notifyChannel("import", netsvc.LOG_ERROR,
648 tools.exception_to_unicode(e))650 tools.exception_to_unicode(e))
@@ -652,10 +654,10 @@
652 try:654 try:
653 _check_db_id(self, model_rel, line[i])655 _check_db_id(self, model_rel, line[i])
654 res = line[i]656 res = line[i]
655 except Exception,e: 657 except Exception,e:
656 warning += [tools.exception_to_unicode(e)]658 warning += [tools.exception_to_unicode(e)]
657 logger.notifyChannel("import", netsvc.LOG_ERROR,659 logger.notifyChannel("import", netsvc.LOG_ERROR,
658 tools.exception_to_unicode(e)) 660 tools.exception_to_unicode(e))
659 row[field_name] = res or False661 row[field_name] = res or False
660 continue662 continue
661663
@@ -668,7 +670,7 @@
668 if '.' in word:670 if '.' in word:
669 module, xml_id = word.rsplit('.', 1)671 module, xml_id = word.rsplit('.', 1)
670 else:672 else:
671 module, xml_id = current_module, word 673 module, xml_id = current_module, word
672 id = ir_model_data_obj._get_id(cr, uid, module,674 id = ir_model_data_obj._get_id(cr, uid, module,
673 xml_id)675 xml_id)
674 res_id2 = ir_model_data_obj.read(cr, uid, [id],676 res_id2 = ir_model_data_obj.read(cr, uid, [id],
@@ -681,7 +683,7 @@
681 if '.' in line[i]:683 if '.' in line[i]:
682 module, xml_id = line[i].rsplit('.', 1)684 module, xml_id = line[i].rsplit('.', 1)
683 else:685 else:
684 module, xml_id = current_module, line[i] 686 module, xml_id = current_module, line[i]
685687
686 record_id = ir_model_data_obj._get_id(cr, uid, module, xml_id)688 record_id = ir_model_data_obj._get_id(cr, uid, module, xml_id)
687 ir_model_data = ir_model_data_obj.read(cr, uid, [record_id], ['res_id'])689 ir_model_data = ir_model_data_obj.read(cr, uid, [record_id], ['res_id'])
@@ -699,31 +701,31 @@
699 continue701 continue
700 if (len(field) == len(prefix)+1) and \702 if (len(field) == len(prefix)+1) and \
701 (prefix == field[0:len(prefix)]):703 (prefix == field[0:len(prefix)]):
702 if field[len(prefix)] == "id": 704 if field[len(prefix)] == "id":
703 # XML ID 705 # XML ID
704 db_id = False 706 db_id = False
705 is_xml_id = data_id = line[i] 707 is_xml_id = data_id = line[i]
706 d = data_id.split('.')708 d = data_id.split('.')
707 module = len(d)>1 and d[0] or ''709 module = len(d)>1 and d[0] or ''
708 name = len(d)>1 and d[1] or d[0] 710 name = len(d)>1 and d[1] or d[0]
709 data_ids = ir_model_data_obj.search(cr, uid, [('module','=',module),('model','=',model_name),('name','=',name)]) 711 data_ids = ir_model_data_obj.search(cr, uid, [('module','=',module),('model','=',model_name),('name','=',name)])
710 if len(data_ids):712 if len(data_ids):
711 d = ir_model_data_obj.read(cr, uid, data_ids, ['res_id'])[0] 713 d = ir_model_data_obj.read(cr, uid, data_ids, ['res_id'])[0]
712 db_id = d['res_id'] 714 db_id = d['res_id']
713 if is_db_id and not db_id:715 if is_db_id and not db_id:
714 data_ids = ir_model_data_obj.search(cr, uid, [('module','=',module),('model','=',model_name),('res_id','=',is_db_id)]) 716 data_ids = ir_model_data_obj.search(cr, uid, [('module','=',module),('model','=',model_name),('res_id','=',is_db_id)])
715 if not len(data_ids):717 if not len(data_ids):
716 ir_model_data_obj.create(cr, uid, {'module':module, 'model':model_name, 'name':name, 'res_id':is_db_id}) 718 ir_model_data_obj.create(cr, uid, {'module':module, 'model':model_name, 'name':name, 'res_id':is_db_id})
717 db_id = is_db_id 719 db_id = is_db_id
718 if is_db_id and int(db_id) != int(is_db_id): 720 if is_db_id and int(db_id) != int(is_db_id):
719 warning += [_("Id is not the same than existing one: %s")%(is_db_id)]721 warning += [_("Id is not the same than existing one: %s")%(is_db_id)]
720 logger.notifyChannel("import", netsvc.LOG_ERROR,722 logger.notifyChannel("import", netsvc.LOG_ERROR,
721 _("Id is not the same than existing one: %s")%(is_db_id))723 _("Id is not the same than existing one: %s")%(is_db_id))
722 continue724 continue
723725
724 if field[len(prefix)] == "db_id":726 if field[len(prefix)] == "db_id":
725 # Database ID 727 # Database ID
726 try: 728 try:
727 _check_db_id(self, model_name, line[i])729 _check_db_id(self, model_name, line[i])
728 data_res_id = is_db_id = int(line[i])730 data_res_id = is_db_id = int(line[i])
729 except Exception,e:731 except Exception,e:
@@ -733,19 +735,19 @@
733 continue735 continue
734 data_ids = ir_model_data_obj.search(cr, uid, [('model','=',model_name),('res_id','=',line[i])])736 data_ids = ir_model_data_obj.search(cr, uid, [('model','=',model_name),('res_id','=',line[i])])
735 if len(data_ids):737 if len(data_ids):
736 d = ir_model_data_obj.read(cr, uid, data_ids, ['name','module'])[0] 738 d = ir_model_data_obj.read(cr, uid, data_ids, ['name','module'])[0]
737 data_id = d['name'] 739 data_id = d['name']
738 if d['module']:740 if d['module']:
739 data_id = '%s.%s'%(d['module'],d['name'])741 data_id = '%s.%s'%(d['module'],d['name'])
740 else:742 else:
741 data_id = d['name']743 data_id = d['name']
742 if is_xml_id and not data_id:744 if is_xml_id and not data_id:
743 data_id = is_xml_id 745 data_id = is_xml_id
744 if is_xml_id and is_xml_id!=data_id: 746 if is_xml_id and is_xml_id!=data_id:
745 warning += [_("Id is not the same than existing one: %s")%(line[i])]747 warning += [_("Id is not the same than existing one: %s")%(line[i])]
746 logger.notifyChannel("import", netsvc.LOG_ERROR,748 logger.notifyChannel("import", netsvc.LOG_ERROR,
747 _("Id is not the same than existing one: %s")%(line[i]))749 _("Id is not the same than existing one: %s")%(line[i]))
748 750
749 continue751 continue
750 if fields_def[field[len(prefix)]]['type'] == 'integer':752 if fields_def[field[len(prefix)]]['type'] == 'integer':
751 res = line[i] and int(line[i])753 res = line[i] and int(line[i])
@@ -769,9 +771,9 @@
769 logger.notifyChannel("import", netsvc.LOG_WARNING,771 logger.notifyChannel("import", netsvc.LOG_WARNING,
770 _("key '%s' not found in selection field '%s'") % \772 _("key '%s' not found in selection field '%s'") % \
771 (line[i], field[len(prefix)]))773 (line[i], field[len(prefix)]))
772 774
773 warning += [_("Key/value '%s' not found in selection field '%s'")%(line[i],field[len(prefix)])]775 warning += [_("Key/value '%s' not found in selection field '%s'")%(line[i],field[len(prefix)])]
774 776
775 elif fields_def[field[len(prefix)]]['type']=='many2one':777 elif fields_def[field[len(prefix)]]['type']=='many2one':
776 res = False778 res = False
777 if line[i]:779 if line[i]:
@@ -814,13 +816,13 @@
814 relation_obj = self.pool.get(fields_def[field]['relation'])816 relation_obj = self.pool.get(fields_def[field]['relation'])
815 newfd = relation_obj.fields_get(817 newfd = relation_obj.fields_get(
816 cr, uid, context=context)818 cr, uid, context=context)
817 res = process_liness(self, datas, prefix + [field], current_module, relation_obj._name, newfd, position) 819 res = process_liness(self, datas, prefix + [field], current_module, relation_obj._name, newfd, position)
818 (newrow, max2, w2, translate2, data_id2, data_res_id2) = res 820 (newrow, max2, w2, translate2, data_id2, data_res_id2) = res
819 nbrmax = max(nbrmax, max2)821 nbrmax = max(nbrmax, max2)
820 warning = warning + w2 822 warning = warning + w2
821 reduce(lambda x, y: x and y, newrow) 823 reduce(lambda x, y: x and y, newrow)
822 row[field] = newrow and (reduce(lambda x, y: x or y, newrow.values()) and \824 row[field] = newrow and (reduce(lambda x, y: x or y, newrow.values()) and \
823 [(0, 0, newrow)]) or [] 825 [(0, 0, newrow)]) or []
824 i = max2826 i = max2
825 while (position+i)<len(datas):827 while (position+i)<len(datas):
826 ok = True828 ok = True
@@ -835,7 +837,7 @@
835 self, datas, prefix+[field], current_module, relation_obj._name, newfd, position+i)837 self, datas, prefix+[field], current_module, relation_obj._name, newfd, position+i)
836 warning = warning+w2838 warning = warning+w2
837 if newrow and reduce(lambda x, y: x or y, newrow.values()):839 if newrow and reduce(lambda x, y: x or y, newrow.values()):
838 row[field].append((0, 0, newrow)) 840 row[field].append((0, 0, newrow))
839 i += max2841 i += max2
840 nbrmax = max(nbrmax, i)842 nbrmax = max(nbrmax, i)
841843
@@ -884,7 +886,7 @@
884 return (-1, res, 'Line ' + str(counter) +' : ' + msg, '' )886 return (-1, res, 'Line ' + str(counter) +' : ' + msg, '' )
885 #Raising Uncaught exception887 #Raising Uncaught exception
886 return (-1, res, 'Line ' + str(counter) +' : ' + str(e), '' )888 return (-1, res, 'Line ' + str(counter) +' : ' + str(e), '' )
887 889
888 for lang in translate:890 for lang in translate:
889 context2 = context.copy()891 context2 = context.copy()
890 context2['lang'] = lang892 context2['lang'] = lang
@@ -1130,15 +1132,15 @@
1130 if user != 1: # admin user has all roles1132 if user != 1: # admin user has all roles
1131 user_roles = usersobj.read(cr, user, [user], ['roles_id'])[0]['roles_id']1133 user_roles = usersobj.read(cr, user, [user], ['roles_id'])[0]['roles_id']
1132 # TODO handle the case of more than one workflow for a model1134 # TODO handle the case of more than one workflow for a model
1133 cr.execute("""SELECT DISTINCT t.role_id 1135 cr.execute("""SELECT DISTINCT t.role_id
1134 FROM wkf 1136 FROM wkf
1135 INNER JOIN wkf_activity a ON a.wkf_id = wkf.id 1137 INNER JOIN wkf_activity a ON a.wkf_id = wkf.id
1136 INNER JOIN wkf_transition t ON (t.act_to = a.id)1138 INNER JOIN wkf_transition t ON (t.act_to = a.id)
1137 WHERE wkf.osv = %s1139 WHERE wkf.osv = %s
1138 AND t.signal = %s1140 AND t.signal = %s
1139 """, (self._name, button.get('name'),))1141 """, (self._name, button.get('name'),))
1140 roles = cr.fetchall()1142 roles = cr.fetchall()
1141 1143
1142 # draft -> valid = signal_next (role X)1144 # draft -> valid = signal_next (role X)
1143 # draft -> cancel = signal_cancel (no role)1145 # draft -> cancel = signal_cancel (no role)
1144 #1146 #
@@ -1147,13 +1149,13 @@
1147 #1149 #
1148 # running -> done = signal_next (role Z)1150 # running -> done = signal_next (role Z)
1149 # running -> cancel = signal_cancel (role Z)1151 # running -> cancel = signal_cancel (role Z)
1150 # As we don't know the object state, in this scenario, 1152 # As we don't know the object state, in this scenario,
1151 # the button "signal_cancel" will be always shown as there is no restriction to cancel in draft1153 # the button "signal_cancel" will be always shown as there is no restriction to cancel in draft
1152 # the button "signal_next" will be show if the user has any of the roles (X Y or Z)1154 # the button "signal_next" will be show if the user has any of the roles (X Y or Z)
1153 # The verification will be made later in workflow process...1155 # The verification will be made later in workflow process...
1154 if roles:1156 if roles:
1155 can_click = any((not role) or rolesobj.check(cr, user, user_roles, role) for (role,) in roles)1157 can_click = any((not role) or rolesobj.check(cr, user, user_roles, role) for (role,) in roles)
1156 1158
1157 button.set('readonly', str(int(not can_click)))1159 button.set('readonly', str(int(not can_click)))
11581160
1159 arch = etree.tostring(node, encoding="utf-8").replace('\t', '')1161 arch = etree.tostring(node, encoding="utf-8").replace('\t', '')
@@ -1665,7 +1667,7 @@
1665 def _check_removed_columns(self, cr, log=False):1667 def _check_removed_columns(self, cr, log=False):
1666 # nothing to check in memory...1668 # nothing to check in memory...
1667 pass1669 pass
1668 1670
1669 def exists(self, cr, uid, id, context=None):1671 def exists(self, cr, uid, id, context=None):
1670 return id in self.datas1672 return id in self.datas
16711673
@@ -1804,12 +1806,12 @@
18041806
1805 if isinstance(f, fields.one2many):1807 if isinstance(f, fields.one2many):
1806 cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname=%s", (f._obj,))1808 cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname=%s", (f._obj,))
1807 1809
1808 if self.pool.get(f._obj):1810 if self.pool.get(f._obj):
1809 if f._fields_id not in self.pool.get(f._obj)._columns.keys():1811 if f._fields_id not in self.pool.get(f._obj)._columns.keys():
1810 if not self.pool.get(f._obj)._inherits or (f._fields_id not in self.pool.get(f._obj)._inherit_fields.keys()):1812 if not self.pool.get(f._obj)._inherits or (f._fields_id not in self.pool.get(f._obj)._inherit_fields.keys()):
1811 raise except_orm('Programming Error', ("There is no reference field '%s' found for '%s'") % (f._fields_id,f._obj,))1813 raise except_orm('Programming Error', ("There is no reference field '%s' found for '%s'") % (f._fields_id,f._obj,))
1812 1814
1813 if cr.fetchone():1815 if cr.fetchone():
1814 cr.execute("SELECT count(1) as c FROM pg_class c,pg_attribute a WHERE c.relname=%s AND a.attname=%s AND c.oid=a.attrelid", (f._obj, f._fields_id))1816 cr.execute("SELECT count(1) as c FROM pg_class c,pg_attribute a WHERE c.relname=%s AND a.attname=%s AND c.oid=a.attrelid", (f._obj, f._fields_id))
1815 res = cr.fetchone()[0]1817 res = cr.fetchone()[0]
@@ -1916,7 +1918,7 @@
1916 field_size = (65535 * f.digits[0]) + f.digits[0] + f.digits[1]1918 field_size = (65535 * f.digits[0]) + f.digits[0] + f.digits[1]
1917 if field_size != f_pg_size:1919 if field_size != f_pg_size:
1918 field_size_change = True1920 field_size_change = True
1919 1921
1920 if f_pg_type != f_obj_type or field_size_change:1922 if f_pg_type != f_obj_type or field_size_change:
1921 if f_pg_type != f_obj_type:1923 if f_pg_type != f_obj_type:
1922 logger.notifyChannel('orm', netsvc.LOG_INFO, "column '%s' in table '%s' changed type to %s." % (k, self._table, c[1]))1924 logger.notifyChannel('orm', netsvc.LOG_INFO, "column '%s' in table '%s' changed type to %s." % (k, self._table, c[1]))
@@ -2004,11 +2006,11 @@
2004 create = not bool(cr.fetchone())2006 create = not bool(cr.fetchone())
20052007
2006 cr.commit() # start a new transaction2008 cr.commit() # start a new transaction
2007 2009
2008 store_fncts = self.pool._store_function.get(self._name, [])2010 store_fncts = self.pool._store_function.get(self._name, [])
2009 #if any field is changed from function to storable, we need to remove its entry from store_function2011 #if any field is changed from function to storable, we need to remove its entry from store_function
2010 remove_stores = []2012 remove_stores = []
2011 2013
2012 for record in store_fncts:2014 for record in store_fncts:
2013 if record[0] == self._name and (self._columns.get(record[1],False) or self._inherit_fields.get(record[1],False)):2015 if record[0] == self._name and (self._columns.get(record[1],False) or self._inherit_fields.get(record[1],False)):
2014 if (not isinstance(self._columns[record[1]],fields.function)) or (record[1] in self._inherit_fields and not isinstance(self._inherit_fields[record[1]][2],fields.function)):2016 if (not isinstance(self._columns[record[1]],fields.function)) or (record[1] in self._inherit_fields and not isinstance(self._inherit_fields[record[1]][2],fields.function)):
@@ -2018,7 +2020,7 @@
2018 store_fncts.remove(stores)2020 store_fncts.remove(stores)
20192021
2020 self.pool._store_function[self._name] = store_fncts2022 self.pool._store_function[self._name] = store_fncts
2021 2023
2022 for (key, con, _) in self._sql_constraints:2024 for (key, con, _) in self._sql_constraints:
2023 conname = '%s_%s' % (self._table, key)2025 conname = '%s_%s' % (self._table, key)
2024 cr.execute("SELECT conname FROM pg_constraint where conname=%s", (conname,))2026 cr.execute("SELECT conname FROM pg_constraint where conname=%s", (conname,))
@@ -2306,7 +2308,7 @@
2306 res.extend(cr.dictfetchall())2308 res.extend(cr.dictfetchall())
2307 else:2309 else:
2308 res = map(lambda x: {'id': x}, ids)2310 res = map(lambda x: {'id': x}, ids)
2309 2311
2310# if not res:2312# if not res:
2311# res = map(lambda x: {'id': x}, ids)2313# res = map(lambda x: {'id': x}, ids)
2312# for record in res:2314# for record in res:
@@ -2321,7 +2323,7 @@
2321# if ftype in ('one2many', 'many2many'):2323# if ftype in ('one2many', 'many2many'):
2322# field_val = []2324# field_val = []
2323# record.update({f:field_val})2325# record.update({f:field_val})
2324 2326
2325 for f in fields_pre:2327 for f in fields_pre:
2326 if f == self.CONCURRENCY_CHECK_FIELD:2328 if f == self.CONCURRENCY_CHECK_FIELD:
2327 continue2329 continue
@@ -2481,8 +2483,8 @@
2481 self.pool.get('ir.model.access').check(cr, uid, self._name, 'unlink', context=context)2483 self.pool.get('ir.model.access').check(cr, uid, self._name, 'unlink', context=context)
24822484
2483 properties = self.pool.get('ir.property')2485 properties = self.pool.get('ir.property')
2484 domain = [('res_id', '=', False), 2486 domain = [('res_id', '=', False),
2485 ('value', 'in', ['%s,%s' % (self._name, i) for i in ids]), 2487 ('value', 'in', ['%s,%s' % (self._name, i) for i in ids]),
2486 ]2488 ]
2487 if properties.search(cr, uid, domain, context=context):2489 if properties.search(cr, uid, domain, context=context):
2488 raise except_orm(_('Error'), _('Unable to delete this document because it is used as a default property'))2490 raise except_orm(_('Error'), _('Unable to delete this document because it is used as a default property'))
@@ -2717,10 +2719,10 @@
2717 cr.execute('SELECT parent_left, parent_right FROM "%s" WHERE id=%%s' % (self._table,), (id,))2719 cr.execute('SELECT parent_left, parent_right FROM "%s" WHERE id=%%s' % (self._table,), (id,))
2718 pleft, pright = cr.fetchone()2720 pleft, pright = cr.fetchone()
2719 distance = pright - pleft + 12721 distance = pright - pleft + 1
2720 2722
2721 cr.execute('SELECT parent_right, id FROM "%s" WHERE %s ORDER BY %s' % (self._table, clause, order), params)2723 cr.execute('SELECT parent_right, id FROM "%s" WHERE %s ORDER BY %s' % (self._table, clause, order), params)
2722 parents = cr.fetchall()2724 parents = cr.fetchall()
2723 2725
2724 # Find Position of the element2726 # Find Position of the element
2725 position = None2727 position = None
2726 for (parent_pright, parent_id) in parents:2728 for (parent_pright, parent_id) in parents:
@@ -2760,7 +2762,7 @@
2760 done[key][id] = True2762 done[key][id] = True
2761 todo.append(id)2763 todo.append(id)
2762 self.pool.get(object)._store_set_values(cr, user, todo, fields_to_recompute, context)2764 self.pool.get(object)._store_set_values(cr, user, todo, fields_to_recompute, context)
2763 2765
2764 wf_service = netsvc.LocalService("workflow")2766 wf_service = netsvc.LocalService("workflow")
2765 for id in ids:2767 for id in ids:
2766 wf_service.trg_write(user, self._name, id, cr)2768 wf_service.trg_write(user, self._name, id, cr)
@@ -2843,15 +2845,15 @@
2843 upd0 += ','+self._inherits[table]2845 upd0 += ','+self._inherits[table]
2844 upd1 += ',%s'2846 upd1 += ',%s'
2845 upd2.append(record_id)2847 upd2.append(record_id)
2846 2848
2847 #Start : Set bool fields to be False if they are not touched(to make search more powerful) 2849 #Start : Set bool fields to be False if they are not touched(to make search more powerful)
2848 bool_fields = [x for x in self._columns.keys() if self._columns[x]._type=='boolean']2850 bool_fields = [x for x in self._columns.keys() if self._columns[x]._type=='boolean']
2849 2851
2850 for bool_field in bool_fields:2852 for bool_field in bool_fields:
2851 if bool_field not in vals:2853 if bool_field not in vals:
2852 vals[bool_field] = False2854 vals[bool_field] = False
2853 #End2855 #End
2854 2856
2855 for field in vals:2857 for field in vals:
2856 if field in self._columns:2858 if field in self._columns:
2857 if self._columns[field]._classic_write:2859 if self._columns[field]._classic_write:
@@ -2909,13 +2911,13 @@
2909 cr.execute('update '+self._table+' set parent_left=parent_left+2 where parent_left>%s', (pleft,))2911 cr.execute('update '+self._table+' set parent_left=parent_left+2 where parent_left>%s', (pleft,))
2910 cr.execute('update '+self._table+' set parent_right=parent_right+2 where parent_right>%s', (pleft,))2912 cr.execute('update '+self._table+' set parent_right=parent_right+2 where parent_right>%s', (pleft,))
2911 cr.execute('update '+self._table+' set parent_left=%s,parent_right=%s where id=%s', (pleft+1,pleft+2,id_new))2913 cr.execute('update '+self._table+' set parent_left=%s,parent_right=%s where id=%s', (pleft+1,pleft+2,id_new))
2912 2914
2913 # default element in context must be removed when call a one2many or many2many2915 # default element in context must be removed when call a one2many or many2many
2914 rel_context = context.copy()2916 rel_context = context.copy()
2915 for c in context.items():2917 for c in context.items():
2916 if c[0].startswith('default_'):2918 if c[0].startswith('default_'):
2917 del rel_context[c[0]]2919 del rel_context[c[0]]
2918 2920
2919 result = []2921 result = []
2920 for field in upd_todo:2922 for field in upd_todo:
2921 result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or []2923 result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or []