- In order to check dynamic folder functionality of document + FTP - !python {model: ir.attachment}: | from document_ftp import test_easyftp as te ftp = te.get_plain_ftp(timeout=1.0) - | I create two partners 'Partner1' and 'Partner2'. I create three partner categories: 'none', 'pat1' and 'all' I attach Partner1 to pat1, Partner1+Partner2 to 'all' - !record {model: res.partner.category, id: tpat_categ_none }: name: 'No partners' - !record {model: res.partner.category, id: tpat_categ_pat1 }: name: 'Pat 1' - !record {model: res.partner.category, id: tpat_categ_all }: name: 'All Partner1+2' - !record {model: res.partner, id: tpartner1 }: name: Partner 1 category_id: - tpat_categ_pat1 - tpat_categ_all - !record {model: res.partner, id: tpartner_2 }: name: 'Partner 2' category_id: - tpat_categ_all - I create a resource folder of partners, by the (none, pat1, all) categories. - !record {model: document.directory, id: dir_tests2 }: name: Partners Testing parent_id: document.dir_root type: ressource ressource_type_id: base.model_res_partner_category domain: [] # TODO - I commit (because FTP operations are on different transaction) - !python {model: document.directory, id: }: | cr.commit() - I browse through ftp in the resource folder, checking that three categories are there. - !python {model: ir.attachment}: | from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing') dirs = ftp.nlst() for dir in [ 'All Partner1+2', 'No partners', 'Pat 1' ]: assert dir in dirs, "Dir %s not in folder" % dir - I create a 'partners' folder by the first resource one. - !record {model: document.directory, id: dir_respart1 }: name: Partners of Test parent_id: dir_tests2 type: ressource ressource_type_id: base.model_res_partner domain: "[('category_id','in',[active_id])]" ressource_parent_type_id : base.model_res_partner_category - !python {model: document.directory, id: }: | cr.commit() - I check through FTP that the correct partners are listed at each 'partners' folder. - !python {model: ir.attachment}: | from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing') correct = { 'All Partner1+2': [ 'Partner 1', 'Partner 2' ], 'No partners': [], 'Pat 1': ['Partner 1',] } for dir in correct: res = ftp.nlst(dir+'/Partners of Test') assert res == correct[dir], "Dir %s falsely contains %s" %(dir, res) - I create an ir.attachment, attached (not related) to Partner1 - !record {model: ir.attachment, id: file_test1 }: name: File of pat1 res_model: res.partner res_id: !eval ref("tpartner1") - I check that pat1/Partner1 folder has the file. I check that all/Partner1 folder has the file - !python {model: ir.attachment}: | from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing') dirs = [ 'All Partner1+2', 'Pat 1' ] for dir in dirs: res = ftp.nlst(dir+'/Partners of Test/Partner 1') assert 'File of pat1' in res, "Dir %s contains only %s" %(dir, res) - I place a file at the 'pat1'/Partner1 folder, through FTP - !python {model: ir.attachment}: | from document_ftp import test_easyftp as te from cStringIO import StringIO ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Partners Testing/Pat 1/Partners of Test/Partner 1') fdata = StringIO('abcd') ftp.storbinary('STOR pat1-dynamic.txt', fdata) - I check at the server that the file is attached to Partner1 - !assert {model: ir.attachment, id: , search: "[('name','=','pat1-dynamic.txt')]" }: - parent_id.name == 'Documents' - res_model == 'res.partner' - res_id != False - I check that all/Partner1 also has the file - | Bonus Piste: I create a 'Partner3' under 'all' - I delete the Partners Testing folder - !python {model: document.directory}: | self.unlink(cr, uid, [ref('dir_tests2')]) self.unlink(cr, uid, [ref('dir_respart1')]) cr.commit()