问题
HI any help please I have this code odoo 10 ,I try to create a one2many relation history_line
the first class
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)),
})
the second class
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)
回答1:
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)),
})
来源:https://stackoverflow.com/questions/47353716/create-record-error