def _get_res_id(self, cr, uid, fields, datas): if 'res_id:id' in fields and 'model_id:id' in fields: res_id_position = fields.index('res_id:id') model_id_position = fields.index('model_id:id') model_data_obj = self.pool.get('ir.model.data') for data in datas: module, xml_id = data[res_id_position].split('.') res_model, res_id = model_data_obj.get_object_reference(cr, uid, module, xml_id) data_model = data[model_id_position].split('.')[1] if res_model.replace('.', '_') != data_model.replace('model_', ''): raise osv.except_osv(_('Error'), _('res_id model and model_id must be identical')) data[res_id_position] = res_id fields[res_id_position] = 'res_id'
def read_group(self, cr, uid, domain, fields=None, group_by_fields=None, p1=False, p2=False, context=None, sort=False): dims = self.pool.get('product.variant.dimension.type').search(cr, uid, []) for dim in self.pool.get('product.variant.dimension.type').browse(cr, uid, dims): if dim.description in fields: del(fields[fields.index(dim.description)]) ret = super(stock_production_lot, self).read_group(cr, uid, domain, fields, group_by_fields, p1, p2, context, sort) return ret
def _remove_bad_fields_values(self, fields, values, bad_fields): for bad_field in bad_fields: i = fields.index(bad_field) fields.pop(i) values.pop(i) return (fields, values)
def import_data(self, cr, uid, fields, datas, mode='init', current_module='', noupdate=False, context=None, filename=None): try: payment_id_pos = fields.index('payment_id') except: payment_id_pos = -1 payment_no_list =[] if payment_id_pos>=0: for lst in datas: payment_no_list.append(lst[payment_id_pos]) payment_nos =str(payment_no_list).replace("[","(").replace("]",")") #",".join(map(str,payment_no_list)) #raise osv.except_osv("KDVN Error",payment_nos) cr.execute("Select paymentno from kdvn_request_of_payment krop where paymentno in %s and state!='completed'" % (payment_nos)) #raise osv.except_osv("KDVN Error",payment_nos) res = cr.fetchall() if res: list =[] for pn in res: list.append(str(pn[0])) raise osv.except_osv("KDVN Error","State of payment must be BOD Approved !\n%s" % str(list)) return super(kdvn_payment, self).import_data(cr, uid, fields, datas,mode, current_module, noupdate, context, filename)
def do_it(self, cr, uid, ids, context=None): """ This function . @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of IDs @param context: A standard dictionary for contextual values @return : an empty dictionary. """ # Here is an example of could be in csv_content # "Qty","prodlot","tracking" # 1,"CNSTP08207030","085511020291554209" # 1,"CNSTP08207030","085511021411014209" # 1,"CNSTP08207030","085511021431334209" # 1,"CNSTP08207030","085511022150614209" # 1,"CNSTP08207030","085511022160244209" # 1,"CNSTP08207031","085511022160804209" # 1,"CNSTP08207031","085511110101200210" # 1,"CNSTP08207031","085511110120020210" # 1,"CNSTP08207031","085511110120740210" # 1,"CNSTP08207031","085511110130070210" # 1,"CNSTP08207031","085511110160080210" # 1,"CNSTP08207031","085511110300360210" if not context: context = {} for id in ids: obj = self.browse(cr, uid, id, context=context) csv_content = base64.decodestring(obj.csv_file).split('\n') # This will facilitate the decoding of the CSV content lines = csv.reader(csv_content, delimiter=',') fields = lines.next() # Here we clean somewhat the list of lines so that we have an idea of how many lines there are i = 0 while(i < len(csv_content)): if len(csv_content[i].strip()) < 1: del csv_content[i] else: i += 1 csv_count = len(csv_content) - 1 move_obj = self.pool.get('stock.move') pick_obj = self.pool.get('stock.picking') prodlot_obj = self.pool.get('stock.production.lot') tracking_obj = self.pool.get('stock.tracking') record_id = context and context.get('active_id', False) or False assert record_id,'Active ID not found' pick = pick_obj.browse(cr, uid, record_id, context=context) if len(pick.move_lines) != 1: continue count = 0 for move in pick.move_lines: if move.product_qty != csv_count: msg = _('The quantity (%d) does not correspond to the number of lines (%d) of the CSV file.' ) % ( move.product_qty, csv_count ) raise osv.except_osv( 'Error!', msg ) # In the future, it may be replaced by one of the CSV's column new_qty = 1.0 new_uos_qty = new_qty / move.product_qty * move.product_uos_qty # loop through the CSV lines tracking_id = False prodlot_id = False for line in lines: vals = {} # Setup the columns and their values for col in self.columns_to_fields.keys(): if col not in fields: continue val = line[ fields.index(col) ] if col == 'prodlot': prodlot_vals = { 'ref': val, 'product_id': move.product_id.id, } prodlot_ids = prodlot_obj.search(cr, uid, [('ref','=',val)], context=context) if not prodlot_ids or len(prodlot_ids) < 1: prodlot_id = prodlot_obj.create(cr, uid, prodlot_vals, context=context) else: prodlot_id = prodlot_ids[0] if prodlot_id: vals[self.columns_to_fields[col]] = prodlot_id elif col == 'tracking': tracking_vals = { 'serial': val, } tracking_ids = tracking_obj.search(cr, uid, [('serial','=',val)], context=context) if not tracking_ids or len(tracking_ids) < 1: tracking_id = tracking_obj.create(cr, uid, tracking_vals, context=context) else: tracking_id = tracking_ids[0] if tracking_id: vals[self.columns_to_fields[col]] = tracking_id elif hasattr(move,self.columns_to_fields[col]): vals[self.columns_to_fields[col]] = val if prodlot_id and tracking_id: tracking_obj.write(cr, uid, [tracking_id], {'prodlot_id':prodlot_id}, context=context) vals.update({'product_qty' : new_qty, 'product_uos_qty': new_uos_qty, 'state':move.state}) if count == 0: move_obj.write(cr, uid, move.id, vals, context=context) else: new_obj = move_obj.copy(cr, uid, move.id, vals) count += 1 return {'type': 'ir.actions.act_window_close'}