How to increment or decrement a recordset? odoo9

2019-09-16 00:56发布

My record set is items = product.pricelist.item(4,3,2)

qty_in_product_uom is passed by the user( 4= min_quantity 500, 3= 250, 2= 100 )

for rule in items:
    if rule.min_quantity and qty_in_product_uom < rule.min_quantity:
        print inside rule.id

now i want such a function that selects the next id if the condition is true

eg. if user passes qty_in_product_uom say 110 then my above if condition will give id=2 in this case i want id=3

if id=3 then answer will be id=4

and if id=4 select id=4

As recordsets are immutable how to achieve this.

1条回答
beautiful°
2楼-- · 2019-09-16 01:26

The recordset(BaseModel class) is an iterable Python object. That means you can use the object in almost the same way you use a list. For example:

item = product.pricelist.item(4,3,2)[0]

print item # This will print product.pricelist.item(4,)

If you want to get a record from the recordset using its id you can use:

item = product.pricelist.item(4,3,2).index(3)

print item # This will print product.pricelist.item(3,)

查看更多
登录 后发表回答