mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
#I9QR3B app_auto_backup增加从界面下载删除备份库的功能
This commit is contained in:
36
app_auto_backup/models/db_backup_details.py
Normal file
36
app_auto_backup/models/db_backup_details.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class DbBackupDetails(models.Model):
|
||||
_name = 'db.backup.details'
|
||||
_description = 'Database Backup Details'
|
||||
|
||||
name = fields.Char(string='Name')
|
||||
file_path = fields.Char(string="File Path")
|
||||
url = fields.Char(string='URL')
|
||||
db_backup_id = fields.Many2one('db.backup', 'Database Backup')
|
||||
|
||||
def action_download_file(self):
|
||||
self.ensure_one()
|
||||
if not self.file_path or not self.url:
|
||||
raise UserError(_("File Path or URL not found."))
|
||||
else:
|
||||
return {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': self.url,
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
def unlink(self):
|
||||
if self.file_path:
|
||||
if os.path.exists(self.file_path):
|
||||
os.remove(self.file_path)
|
||||
return super(DbBackupDetails, self).unlink()
|
||||
|
||||
def action_remove_file(self):
|
||||
self.ensure_one()
|
||||
self.unlink()
|
||||
Reference in New Issue
Block a user