Navigation

    Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    function类型的字段,怎么在试图做筛选条件啊???????????

    Odoo 新手求助
    2
    3
    1894
    Loading More Posts
    • 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.
    • W
      winbo last edited by

      def _get_stock_qty(self, cr, uid, ids, field_names=None, arg=False, context=None):
      res = {}
      print ids
      if len(ids) == 0:
      return res
      if context and context.has_key('location'):
      for id in ids:
      cr.execute(
      '''select stock_qty get_stock_qty from starmerx_inventory where location_id=%s and type='shelf' and product_id=%s''',
      (context.get('location'), id,))
      result = cr.dictfetchall()
      if result:
      res[id] = result[0]['get_stock_qty']
      else:
      print id
      res[id] = 0
      return res

      字段的定义:不保存在数据库
      _columns = {
      'get_newstock_qty': fields.function(_get_stock_qty, string=u"库存数量", type='integer'),
      }

      我现在想搜索库存大于0的。在xml
      《filter string="库存大于0" domain="[('get_newstock_qty', '>', '0')]"/》
      不起作用。何解?

      Felix_Cheng 1 Reply Last reply Reply Quote 0
      • Felix_Cheng
        Felix_Cheng @winbo last edited by Felix_Cheng

        @winbo
        def _get_stock_qty:
        此处是你的代码.....

        #猜测你的代码应该是在product对象上,所以搜索stock_qty大于0的product_id,返回标准domain三元组: [('xxx', 'operator', 'yyy')], 其中 xxx: id, yyy: Search value.
        def _search_positive_stock(self, cr, uid, ids, field_names, args, context=None):
             if context and context.has_key('location'):
                 cr.execute(
                '''select product_id from starmerx_inventory st_inv where location_id=%s and type='shelf' and product_id in %s where st_inv.stock_qty>0''', (context.get('location'), ids,))
                 res = cr.fetchall()
                 if res:
                     return [('id', 'in', [x[0] for x in res])]
            return [('id', '=', 0)]
        @以上代码尚未经过调试,写的只是思路.
        #fnct_search:加上此属性来允许搜索get_newstock_qty函数字段
        _columns = {
        'get_newstock_qty': fields.function(_get_stock_qty, string=u"库存数量", type='integer', fnct_search=_search_positive_stock),
        }

        xml: <filter string="库存大于0" domain="[('get_newstock_qty', '>', 0)]"/>

        W 1 Reply Last reply Reply Quote 0
        • W
          winbo @Felix_Cheng last edited by

          @Felix_Cheng 非常感谢 您能抽取宝贵时间来回答,有这个思路我就知道了。太感谢了!!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post