Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

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

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

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

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

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

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

    Odoo 新手求助
    2
    3
    2108
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • W
      winbo 最后由 编辑

      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 条回复 最后回复 回复 引用 0
      • Felix_Cheng
        Felix_Cheng @winbo 最后由 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)]"/>

        Felix / TriangleERP inc. / QC / CA

        W 1 条回复 最后回复 回复 引用 0
        • W
          winbo @Felix_Cheng 最后由 编辑

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

          1 条回复 最后回复 回复 引用 0
          • First post
            Last post