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

Tanzil Khan picture Tanzil Khan · Oct 26, 2016 · Viewed 7.7k times · Source

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?

Answer

CZoellner picture CZoellner · Oct 26, 2016

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.

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