class lastfile(models.Model):
_name = "lastfile"
_description = "最新文件"
_inherit = ['mail.thread']
name = fields.Char("文件标题")
udate_file = fields.Many2many('ir.attachment', string=u'上传附件')
udate_file_dir = fields.Char(string="附件路径")
demo_order_name = fields.Char(string="附件名称")
url = fields.Char(string="本地下载")
@api.onchange('udate_file')
def _onchange_udate_file(self):
# 如果上传文件对象集合有内容
if self.udate_file:
# 循环文件对象集合
for d in self.udate_file:
# 转换格式
content_base64 = base64.b64decode(d.datas)
dir = os.getcwd()
time_str = str(time.time_ns())
path = dir + '/appstore/project/static/document/' + time_str + d.name
if not os.path.exists(path):
with open(path, mode='wb+') as ff:
ff.write(content_base64)
# 保存附件路径
for i in self:
i.udate_file_dir = path
i.demo_order_name = d.name
i.url = '/project/static/document/' + time_str + d.name
Odoo 文件上传保存URL
最新推荐文章于 2022-04-28 18:15:30 发布