if eqp_id:
for rule in items:
if rule.eqp_pricelist == True:
print "id 1"
print rule.id
continue
print "id 2 out"
print rule.id
#outputs:
#id1
#5
#id 2 out
#4
rule.id = 5
rule.id = 4
怎么可能出现?
此代码适用于product_pricelist方法:
def _price_rule_get_multi(self, cr, uid, pricelist, products_by_qty_by_partner, context=None):
答案 0 :(得分:2)
正如您在评论中所述,如果使用items
获取items = self.pool.get('product.pricelist.item').browse(cr, uid, item_ids, context=context)
,则items
是Odoo ORM的“记录集”,因此您可以使用 {{ 1}} Odoo ORM(see documentation)的功能:
sorted()
返回订购的记录集sorted(key=None, reverse=False)
self
。<强>参数强>:
key - 一个参数的函数,返回每个记录的比较键,或者None,在这种情况下,记录按照默认模型的顺序排序
反向 - 如果为True,则以相反的顺序返回结果
为了将此功能应用于您的代码,请按以下步骤进行更改:
key
编辑:
我没有清楚地看到您的目标,但另请查看if eqp_id:
for rule in items.sorted(key=lambda r: r.id): ## sort by id using sort()...
if rule.eqp_pricelist == True:
print "id 1"
print rule.id
continue
print "id 2 out"
print rule.id
是否可以帮助您:
filtered()
或者:
if eqp_id:
for rule in items.sorted(key=lambda r: r.id).filtered(lambda r: r.eqp_pricelist == True): ## sort by id using sort() AND filtered using eqp_pricelist == True...
print "[True?] Rule with eqp_pricelist == %s" % rule.eqp_pricelist
print rule.id
您也可以仅if eqp_id:
for rule in items.sorted(key=lambda r: r.id).filtered(lambda r: r.eqp_pricelist == Talse): ## sort by id using sort() AND filtered using eqp_pricelist == False...
print "[False?] Rule with eqp_pricelist == %s" % rule.eqp_pricelist
print rule.id
申请filtered()
。
看看这个:sorted()