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


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

  • 相关阅读:
    RichEdit
    用 RAD Studio 柏林版创建 IoT 应用程序
    延时程序
    SQL if exists用法
    Firemonkey限制TEdit只能输入数字的完美方法
    leetcode 树
    leetcode string
    clone-graph
    surrounded-regions merge-intervals
    leetcode链表题
  • 原文地址:https://www.cnblogs.com/qianxunman/p/14898382.html
Copyright © 2011-2022 走看看