'Cancels the moves and if all moves are cancelled it cancels the picking.'

@api.multi
def action_cancel(self):

    if any(((move.state == 'done') for move in self)):
        raise UserError(_("You    cannot    cancel    a    stock    move    that    has    been    set    to    'Done'."))
    procurements = self.env['procurement.order']
    for move in self:
        if move.reserved_quant_ids:
            move.quants_unreserve()
        if self.env.context.get('cancel_procurement'):
            if move.propagate:
                pass
        else:
            if move.move_dest_id:
                if move.propagate:
                    move.move_dest_id.action_cancel()
                elif (move.move_dest_id.state == 'waiting'):
                    move.move_dest_id.write({'state': 'confirmed'})
            if move.procurement_id:
                procurements |= move.procurement_id
    self.write({'state': 'cancel', 'move_dest_id': False})
    if procurements:
        procurements.check()
    return True
