跳至内容
菜单
此问题已终结

Can someone explain how this line is gonna work? Also the lambda function too...(code from sale.order in sale.py)

for line in order.order_line.sorted(key=lambda l: l.qty_to_invoice < 0):

Also if I how to sort the order_line according to the product type (service, consumable, or stockable), so that the order lines are selected according to the their type. (ie, first all the consumable products in the order_line are selected and executed, then all service type, etc....)

形象
丢弃
最佳答案

Hi Naksha,

The sorted() function is a builtin Python function. When you execute this function it will return a sorted list of data from the given iteratable. The lambda call is an anonymous function, which has no function name. It is usually used to quickly handle looping over data and filtering something out. In this it will filter out the lines where the qty_to_invoice < 0.
You can find more information about the sorted() function in the official docs at https://docs.python.org/3/library/functions.html#sorted and more about the lambda function at https://docs.python.org/3/reference/expressions.html#lambda 

In short this line of code it will loop over all order_line values (which is a recordset) which are already sorted and only contain the values where the qty_to_invoice <= 0.

Regards,
Yenthe

形象
丢弃
相关帖文 回复 查看 活动
1
1月 25
3288
2
8月 24
5787
6
12月 22
8710
1
5月 25
5941
0
3月 24
2054