zoukankan      html  css  js  c++  java
  • odoo 计算字段搜索

    源码示例:

        virtual_available = fields.Float(
            'Forecast Quantity', compute='_compute_quantities', search='_search_virtual_available',
            digits=dp.get_precision('Product Unit of Measure'),
            help="Forecast quantity (computed as Quantity On Hand "
                 "- Outgoing + Incoming)
    "
                 "In a context with a single Stock Location, this includes "
                 "goods stored in this location, or any of its children.
    "
                 "In a context with a single Warehouse, this includes "
                 "goods stored in the Stock Location of this Warehouse, or any "
                 "of its children.
    "
                 "Otherwise, this includes goods stored in any Stock Location "
                 "with 'internal' type.")
        def _search_virtual_available(self, operator, value):
            # TDE FIXME: should probably clean the search methods
            return self._search_product_quantity(operator, value, 'virtual_available')
    
        def _search_product_quantity(self, operator, value, field):
            # TDE FIXME: should probably clean the search methods
            # to prevent sql injections
            if field not in ('qty_available', 'virtual_available', 'incoming_qty', 'outgoing_qty'):
                raise UserError(_('Invalid domain left operand %s') % field)
            if operator not in ('<', '>', '=', '!=', '<=', '>='):
                raise UserError(_('Invalid domain operator %s') % operator)
            if not isinstance(value, (float, int)):
                raise UserError(_('Invalid domain right operand %s') % value)
    
            # TODO: Still optimization possible when searching virtual quantities
            ids = []
            # Order the search on `id` to prevent the default order on the product name which slows
            # down the search because of the join on the translation table to get the translated names.
            for product in self.with_context(prefetch_fields=False).search([], order='id'):
                if OPERATORS[operator](product[field], value):
                    ids.append(product.id)
            return [('id', 'in', ids)]
    

    官网:https://www.odoo.com/zh_CN/forum/help-1/calculated-fields-in-search-filter-possible-118501


    懂得,原来世界如此简单!

  • 相关阅读:
    matplotlib 可视化 —— matplotlib.patches
    Ansi,UTF8,Unicode,ASCII编码的差别
    java.lang.Runnable接口
    wikioi 1051哈希表
    具体解释协方差与协方差矩阵
    基于Android Fragment功能的样例
    大学让我们坠落
    FFTW库+VS2012配置
    Ubuntu下安装eclipse
    SoftReference
  • 原文地址:https://www.cnblogs.com/qianxunman/p/14898382.html
Copyright © 2011-2022 走看看