Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 开发与实施交流
  4. 文件管理模块中的ftp目录文件夹改名

文件管理模块中的ftp目录文件夹改名

Scheduled Pinned Locked Moved Odoo 开发与实施交流
3 Posts 2 Posters 5.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    linyaohui
    wrote on last edited by
    #1

    该模块下的ftp功能很强大,我有个疑问,因为默认的ftp目录(举个例子,产品目录下面的文件夹是命名是用product里面的name来命名的,想修改为命名是用product的code 字段来命名)

    解决方法:
    浏览ducpoment.py,有一段
      if len(obj.fields_get(self.cr, self.uid, ['dirname'])):
                    _dirname_field = 'dirname'

    原来oe的文件管理目录默认是用相应的object里面的dirname字段作为文件夹的名字的,如果该project没有dirname字段会用name名字
    所以,解决方法就是在product。product下增加一个dirname字段,然后让dirname的值和code 的值保持一直,这里用触发器处理


    CREATE OR REPLACE FUNCTION ftpdirname() RETURNS trigger AS $ftpdirname$
        BEGIN
            NEW.dirname := NEW.default_code;
            RETURN NEW;
        END;
    $ftpdirname$ LANGUAGE plpgsql;

    CREATE TRIGGER ftpdirname BEFORE INSERT OR UPDATE ON product_product
        FOR EACH ROW EXECUTE PROCEDURE ftpdirname();


    特别鸣谢shelly,jeff等兄的指导 (其实增加一个function字段的dirname来处理更方便,无奈暂时没通晓,所以在数据库段用触发器完成)

    1 Reply Last reply
    0
    • JoshuaJ Offline
      JoshuaJ Offline
      Joshua
      管理员
      wrote on last edited by
      #2

      可以试试酱紫写

      def _new_dirname(self, cr, uid, ids, field_name, arg, context):<br />&nbsp; &nbsp; &nbsp; &nbsp; res = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; for product in self.browse(cr, uid, ids, context=context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res[product.id] = product.name +&#039; &#039;+ product.default_code<br />&nbsp; &nbsp; &nbsp; &nbsp; return res<br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;dirname&#039;:fields.function(_new_dirname, method=True, string=&#039;dirname&#039;,type=&#039;char&#039;,store=True)<br />&nbsp; &nbsp; }<br />
      


      想要更多还有
      [检测到链接无效,已移除]

      【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

      1 Reply Last reply
      0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Tags
      • Popular
      • Users
      • Groups