Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
5948 มุมมอง

I'm developing a module that uploads specific files via ssh to specific server based on customer creation:

   

class ResPartner(models.Model):
    _name = 'res.partner'
    _inherit = 'res.partner'

    @api.model
    def create(self, vals):
        if vals:
            testfile=open("/tmp/diegotexting.txt", "w")
            testfile.write("Hi, testing odoo 9 ")
            ssh = paramiko.SSHClient() 
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh.connect("foo.org", username="foo", password="foo")
            sftp = ssh.open_sftp()
            sftp.put("/tmp/diegotexting.txt", "/tmp/diegotexting.txt")
            sftp.close()
            ssh.close()
        return super(ResPartner, self).create(vals)



It does upload the file in server "foo.org", the problem is that when I open it, it's blank.

I have tested the upload script outside of odoo enviroment and works well(it doesn't show a blank file).

Does anyone know what could be wrong?


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

@Diego, the problem is probably that the file is still open when you start the upload. The open method will create an empty file, but the write method will only cache the string you want to write to the file. To make sure all the cached information are written to the file you can either use the flush or even better the close method.

testfile=open("/tmp/diegotexting.txt", "w")
testfile.write("Hi, testing odoo 9 ")
testfile.close()

Best regards

Yvan

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
override old api onchange odoov9c แก้ไขแล้ว
1
พ.ย. 16
4258
0
ก.ค. 21
3702
1
ก.พ. 16
4050
2
ต.ค. 24
1295
2
เม.ย. 24
1262