if loop continue 正在再次执行for循环
If loop continue is executing for loop again
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):
正如您在评论中指出的那样,如果使用 items = self.pool.get('product.pricelist.item').browse(cr, uid, item_ids, context=context)
获取 items
,则 items
是 Odoo ORM 的 "recordset",因此您可以使用 sorted()
Odoo ORM函数(see documentation):
sorted(key=None, reverse=False)
Return the recordset self
ordered by
key
.
Parameters:
key -- either a function of one argument that returns a comparison key for each record, or None, in which case records are ordered according the default model's order
reverse -- if True, return the result in reverse order
为了将此函数应用于您的代码,请按如下方式更改它:
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()
。
看看这个:for rule in items.filtered("eqp_pricelist"):
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):
正如您在评论中指出的那样,如果使用 items = self.pool.get('product.pricelist.item').browse(cr, uid, item_ids, context=context)
获取 items
,则 items
是 Odoo ORM 的 "recordset",因此您可以使用 sorted()
Odoo ORM函数(see documentation):
sorted(key=None, reverse=False)
Return the recordsetself
ordered bykey
.Parameters:
key -- either a function of one argument that returns a comparison key for each record, or None, in which case records are ordered according the default model's order
reverse -- if True, return the result in reverse order
为了将此函数应用于您的代码,请按如下方式更改它:
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()
。
看看这个:for rule in items.filtered("eqp_pricelist"):