How to increment or decrement a recordset? odoo9

眉间皱痕 提交于 2019-12-12 03:18:57

问题


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:


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,)



来源:https://stackoverflow.com/questions/39081083/how-to-increment-or-decrement-a-recordset-odoo9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!