• 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • 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

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

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

已定时 已固定 已锁定 已移动 Odoo 新手求助
3 帖子 2 发布者 2138 浏览
    • 从旧到新
    • 从新到旧
    • 最多赞同
回复
  • 在新帖中回复
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • W 离线
    W 离线
    winbo
    写于 最后由 编辑
    #1

    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_ChengF 1 条回复 最后回复
    0
  • Felix_ChengF 离线
    Felix_ChengF 离线
    Felix_Cheng
    在 中回复了winbo 最后由 Felix_Cheng 编辑
    #2

    @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 离线
    W 离线
    winbo
    在 中回复了Felix_Cheng 最后由 编辑
    #3

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

    1 条回复 最后回复
    0

  • 登录

  • 没有帐号? 注册

  • 登录或注册以进行搜索。
  • 第一个帖子
    最后一个帖子
0
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
  • 登录

  • 没有帐号? 注册

  • 登录或注册以进行搜索。