Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python e)提交和打印报告。所以我真的不确定你能不能详细说明你的答案,一个具体的例子应用到上面的代码将是非常好的事实上,查询是好的,最“低效”的部分是在写。。。 class file_reader(models.TransientModel): _name = &_Python_Odoo_Odoo 12 - Fatal编程技术网

Python e)提交和打印报告。所以我真的不确定你能不能详细说明你的答案,一个具体的例子应用到上面的代码将是非常好的事实上,查询是好的,最“低效”的部分是在写。。。 class file_reader(models.TransientModel): _name = &

Python e)提交和打印报告。所以我真的不确定你能不能详细说明你的答案,一个具体的例子应用到上面的代码将是非常好的事实上,查询是好的,最“低效”的部分是在写。。。 class file_reader(models.TransientModel): _name = &,python,odoo,odoo-12,Python,Odoo,Odoo 12,e)提交和打印报告。所以我真的不确定你能不能详细说明你的答案,一个具体的例子应用到上面的代码将是非常好的事实上,查询是好的,最“低效”的部分是在写。。。 class file_reader(models.TransientModel): _name = "rw.file.reader" csv_file = fields.Binary(string='CSV File', required=True) @api.multi def import_csv(self):


e)提交和打印报告。所以我真的不确定你能不能详细说明你的答案,一个具体的例子应用到上面的代码将是非常好的事实上,查询是好的,最“低效”的部分是在写。。。
class file_reader(models.TransientModel):
_name = "rw.file.reader"
csv_file = fields.Binary(string='CSV File', required=True)

@api.multi
def import_csv(self):
    # csv importer handler
    file = base64.b64decode(self.csv_file).decode().split('\n')
    reader = csv.DictReader(file)
    # account.analytic.line
    ignored = []
    time1 = datetime.now()
            
    self._cr.execute('select id, name from project_project where active = true')
    projects = self._cr.fetchall()
    
    self._cr.execute('select id, login from res_users')
    users = self._cr.fetchall()
    
    self._cr.execute('select id, work_email from hr_employee')
    employees = self._cr.fetchall()
    LOG_EVERY_N = 100

    for row in reader:
        project_name = row['Project - Name']
        email = row['User - Email Address']
        project = [item for item in projects if item[1] == project_name]
        
        if len(project) >0:
            user = [item for item in users if item[1] == email]
            employee = [item for item in employees if item[1] == email]
                            
            if len(user)>0 and len(employee)>0:
                task = self.env['project.task'].search([['user_id','=',user[0][0]],
                                                        ['project_id','=',project[0][0] ]],limit=1)
                if task:
                    y = row['Duration'].split(':')   
                    i, j = y[0], y[1]  
                    
                    model = {
                        'project_id': project[0][0],
                        'task_id': task['id'],
                        'employee_id':employee[0][0],
                        'user_id': user[0][0],
                        'date': row['Date'],
                        'unit_amount': int(i) + (float(j) / 60), # Time Spent convertion to float
                        'is_timesheet': True,
                        'billable':  True if row['Billable'] == 'Yes' else False,
                        'nexonia_id':row['ID']
                        }
                    
                    time_sheet = self.env['account.analytic.line'].search([['nexonia_id','=', row['ID']]],limit=1)
                    
                    if time_sheet:
                        model.update({'id':time_sheet.id})
                        self.env['account.analytic.line'].sudo().write(model)
                    else:
                        self.env['account.analytic.line'].sudo().create(model)
            else:
                if email not in ignored:
                    ignored.append(email)
        else:
            if project_name not in ignored:
                ignored.append(project_name)
        
        all_text = 'Nothing ignored'
        if ignored is not None:
            all_text = "\n".join(filter(None, ignored))
            
        message_id = self.env['message.wizard'].create({
            'message': "Import data completed",
            'ignored': all_text
        })
    
    time2 = datetime.now()
    logging.info('total time ------------------------------------------ %s',time2-time1)
    
    return {
        'name': 'Successfull',
        'type': 'ir.actions.act_window',
        'view_mode': 'form',
        'res_model': 'message.wizard',
        # pass the id
        'res_id': message_id.id,
        'target': 'new'
    }