创建记录错误

时间:2017-11-17 15:07:58

标签: openerp odoo-10

我有任何帮助请我有这个代码odoo 10,我尝试创建一个one2many关系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']。创建工作(odoo 10) enter image description here

1 个答案:

答案 0 :(得分:1)

当然它不起作用,因为你在同一时间使用新的+旧api也是不正确的,Odoo 10只支持新的api所以不再有cr或uid或id。你应该使用api multi,所以你的代码应该是这样的:

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)),                                 
                    })