创建记录错误 [英] Create Record Error

查看:85
本文介绍了创建记录错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何帮助,请给我我这个odoo 10代码,我尝试创建一个one2many关系history_line

HI any help please I have this code odoo 10 ,I try to create a one2many relation history_line

头等舱

 class db_backup_ept(models.Model):
_name = 'db.autobackup.ept'

name = fields.Char('Database', size=100, required='True',help='Database you want to schedule backups for')
host = fields.Char('Host', size=100, required='True', default='localhost')
port = fields.Char('Port', size=10, required='True', default='8069')
history_line = fields.One2many('db.backup.line', 'backup_id', 'History', readonly=True)
active = fields.Boolean('Active', default=True) 
def ept_backup(self,cr,uid,ids,db_name,bkup_dir,automatic,ftp_enable,FTP_id,bak_conf,keep_backup_local):
for obj in self:
                backup_status = 'Backup completed successfully at path : %s ' %(tar_file_path)
                self.env['db.backup.line'].create(cr,uid,{
                 'backup_id' : obj.id,
                 'name' : obj.name,
                 'date_time' : time.strftime('%Y-%m-%d %H:%M:%S'),
                 'message' : backup_status,
                 'automatic' : automatic,
                 'done_by' : user_id,
                 'path' : tar_file_path,
                 'file_size' : str(os.path.getsize(tar_file_path)),                                 
                })

第二堂课

class db_backup_line(models.Model):
_name = 'db.backup.line'
backup_id = fields.Many2one('db.autobackup.ept','Backup')
name = fields.Char('DB Name', size=100)
date_time = fields.Datetime('Date', size=100)
path = fields.Text('Backup Path')
file_size = fields.Char('File Size',size=100)
automatic = fields.Boolean('Automatic Backup?')
done_by = fields.Many2one('res.users','Done By')
message = fields.Text('Message')

  db_backup_line()

self.env ['db.backup.line'].create d'ont work(odoo 10)

self.env['db.backup.line'].create d'ont work (odoo 10)

推荐答案

当然,这是行不通的,因为您同时使用new + old api,这也是不正确的,Odoo 10也仅支持新api,因此没有cr或uid或id了.您应该改用api multi,因此您的代码应如下所示:

Ofcourse it will not work because you are using new+old api in the same time which is not correct also Odoo 10 only supports new api so there is no cr or uid or ids anymore. You should use api multi instead,so your code should be like this:

def ept_backup(self ,db_name,bkup_dir,automatic,ftp_enable,FTP_id,bak_conf,keep_backup_local):
        for obj in self:
                    backup_status = 'Backup completed successfully at path : %s ' %(tar_file_path)
                    self.env['db.backup.line'].create({
                     'backup_id' : obj.id,
                     'name' : obj.name,
                     'date_time' : time.strftime('%Y-%m-%d %H:%M:%S'),
                     'message' : backup_status,
                     'automatic' : automatic,
                     'done_by' : user_id,
                     'path' : tar_file_path,
                     'file_size' : str(os.path.getsize(tar_file_path)),                                 
                    })

这篇关于创建记录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆