Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在不同的表中按字段搜索产品_Python_Odoo - Fatal编程技术网

Python 如何在不同的表中按字段搜索产品

Python 如何在不同的表中按字段搜索产品,python,odoo,Python,Odoo,我想在产品中使用名称搜索,通过搜索stock.production.lot 关系库存数量标识、产品标识、批次标识 class ProductProduct(models.Model): _inherit = 'product.product' @api.model def name_search(self, name='', args=None, operator='ilike', limit=100): args = args or []

我想在产品中使用名称搜索,通过搜索
stock.production.lot

关系库存数量标识、产品标识、批次标识

class ProductProduct(models.Model):
    _inherit = 'product.product'

    @api.model
    def name_search(self, name='', args=None, operator='ilike', limit=100):

        args = args or []
        print('arg ',args)
        recs = self.search([('???', operator, name)]  args, limit=limit) #stock_quant_ids.lot_id.name
        print('recs ', recs)
        if not recs.ids:
            return super(ProductProduct, self).name_search(name=name, args=args,
                                                       operator=operator,
                                                       limit=limit)
        return recs.name_get()
试试这个:

@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
    """ search for product using the Lot number """
    args = args or []
    recs = None
    # only perform search by when the name is passed
    if name:
        # don't use limit here
        recs = self.env['stock.production.lot'].search([('name', operator, name)])

    if recs:
        # handle extra filter that was passed by the domain attribute in the XML
        args = expression.AND([args, [('id', 'in', recs.mapped('product_id').ids)]])
        return self.search(args, limit=limit).name_get()

    # no Lot was founded may be the user meant to search by product name
    return super(ProductProduct, self).name_search(name=name,
                                            args=args,
                                            operator=operator,
                                            limit=limit)

在第一个代码中,它提供所有产品,第二个代码不返回任何产品。当我将recs.mapped('product_id').name_get()替换为recs.mapped('product_id').name_get()时,第一个代码起作用。对于语法错误,我没有尝试代码,请检查我的更新,我使用了
而不是
,这就是为什么您需要获取所有产品的原因,这里有一个更好的方法来处理您的需求。这里的问题是,这种行为将出现在你所有的manyOne领域,你真的想这样做吗。如果您不使用上下文来应用此方法,则只有a上下文有一个特殊的键,如果您不知道如何告诉我和我如何让我知道。我可以将此批次名称传递给prod_lot_id吗?您的意思是什么?现在我们在(stock.inventory.line)中输入批次名称,我们获得产品名称,我们仍然需要从多个批次(prod_lot_id)中选择批次,这一场景源于库存调整。