pythonpython-2.7odooodoo-8odoo-9

What does |= (pipe equal) sign do in python?


I saw a piece of code in a project where following is written:

 move = Move.create({
    'name': repair.name,
    'product_id': repair.product_id.id,
    'product_uom': repair.product_uom.id or repair.product_id.uom_id.id,
    'product_uom_qty': repair.product_qty,
    'partner_id': repair.address_id.id,
    'location_id': repair.location_id.id,
    'location_dest_id': repair.location_dest_id.id,
    'restrict_lot_id': repair.lot_id.id,
})
moves |= move
moves.action_done()

What does the |= meaning here?


Solution

  • As @AChampion already mentioned in the first question comment, it could be "bitwise or" or "set union". While this question has Odoo as context, it is "set union" for the Odoo class RecordSet.

    For your example: It's the same as moves = moves | move and means a union of moves and move.

    This class was introduced with the new API on Odoo 8. For other operators look into the official doc of Odoo.